提交 aaaa2d56 编写于 作者: M Martin Kletzander

util: fix potential leak in error codepath

Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
上级 8035f2e6
...@@ -529,6 +529,9 @@ virPidFileConstructPath(bool privileged, ...@@ -529,6 +529,9 @@ virPidFileConstructPath(bool privileged,
const char *progname, const char *progname,
char **pidfile) char **pidfile)
{ {
int ret = -1;
char *rundir = NULL;
if (privileged) { if (privileged) {
/* /*
* This is here just to allow calling this function with * This is here just to allow calling this function with
...@@ -542,29 +545,27 @@ virPidFileConstructPath(bool privileged, ...@@ -542,29 +545,27 @@ virPidFileConstructPath(bool privileged,
if (virAsprintf(pidfile, "%s/run/%s.pid", statedir, progname) < 0) if (virAsprintf(pidfile, "%s/run/%s.pid", statedir, progname) < 0)
goto cleanup; goto cleanup;
} else { } else {
char *rundir = NULL;
mode_t old_umask; mode_t old_umask;
if (!(rundir = virGetUserRuntimeDirectory())) if (!(rundir = virGetUserRuntimeDirectory()))
goto error; goto cleanup;
old_umask = umask(077); old_umask = umask(077);
if (virFileMakePath(rundir) < 0) { if (virFileMakePath(rundir) < 0) {
umask(old_umask); umask(old_umask);
goto error; goto cleanup;
} }
umask(old_umask); umask(old_umask);
if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0) { if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0) {
VIR_FREE(rundir); VIR_FREE(rundir);
goto error; goto cleanup;
} }
VIR_FREE(rundir);
} }
return 0; ret = 0;
cleanup:
error: VIR_FREE(rundir);
return -1; return ret;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册