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>
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;
*/
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;
}