From 6c6f796b74b96ed85a289dc805ba3e39cad2664b Mon Sep 17 00:00:00 2001 Message-Id: <6c6f796b74b96ed85a289dc805ba3e39cad2664b@dist-git> From: Martin Kletzander Date: Wed, 17 Sep 2014 17:11:02 +0200 Subject: [PATCH] util: fix potential leak in error codepath https://bugzilla.redhat.com/show_bug.cgi?id=927369 Signed-off-by: Martin Kletzander (cherry picked from commit aaaa2d56bd47556b6857ecca33e4b28ab36c8488) Signed-off-by: Jiri Denemark --- src/util/virpidfile.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 19ec103..dd29701 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; } -- 2.1.0