mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
util: file: Use g_autofree in virFindFileInPath
Simplify the final lookup loop by freeing memory automatically and thus being able to directly return the result. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
1a288c7e8a
commit
6eac0c5436
@ -1634,10 +1634,9 @@ char *
|
||||
virFindFileInPath(const char *file)
|
||||
{
|
||||
const char *origpath = NULL;
|
||||
char *path = NULL;
|
||||
g_autofree char *path = NULL;
|
||||
char *pathiter;
|
||||
char *pathseg;
|
||||
char *fullpath = NULL;
|
||||
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
@ -1672,14 +1671,12 @@ virFindFileInPath(const char *file)
|
||||
*/
|
||||
pathiter = path;
|
||||
while ((pathseg = strsep(&pathiter, ":")) != NULL) {
|
||||
fullpath = g_strdup_printf("%s/%s", pathseg, file);
|
||||
g_autofree char *fullpath = g_strdup_printf("%s/%s", pathseg, file);
|
||||
if (virFileIsExecutable(fullpath))
|
||||
break;
|
||||
VIR_FREE(fullpath);
|
||||
return g_steal_pointer(&fullpath);
|
||||
}
|
||||
|
||||
VIR_FREE(path);
|
||||
return fullpath;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user