From: Martin Kletzander Date: Sun, 7 Sep 2014 18:07:49 +0000 (+0200) Subject: util: fix potential leak in error codepath X-Git-Tag: CVE-2014-3633~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaaa2d56bd47556b6857ecca33e4b28ab36c8488;p=thirdparty%2Flibvirt.git util: fix potential leak in error codepath Signed-off-by: Martin Kletzander --- diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 19ec103ce8..dd29701a75 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -529,6 +529,9 @@ virPidFileConstructPath(bool privileged, const char *progname, char **pidfile) { + int ret = -1; + char *rundir = NULL; + if (privileged) { /* * This is here just to allow calling this function with @@ -542,29 +545,27 @@ virPidFileConstructPath(bool privileged, if (virAsprintf(pidfile, "%s/run/%s.pid", statedir, progname) < 0) goto cleanup; } else { - char *rundir = NULL; mode_t old_umask; if (!(rundir = virGetUserRuntimeDirectory())) - goto error; + goto cleanup; old_umask = umask(077); if (virFileMakePath(rundir) < 0) { umask(old_umask); - goto error; + goto cleanup; } umask(old_umask); if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0) { VIR_FREE(rundir); - goto error; + goto cleanup; } - VIR_FREE(rundir); } - return 0; - - error: - return -1; + ret = 0; + cleanup: + VIR_FREE(rundir); + return ret; }