提交 6eac0c54 编写于 作者: P Peter Krempa

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NPavel Hrdina <phrdina@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 1a288c7e
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册