]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: fix potential leak in error codepath
authorMartin Kletzander <mkletzan@redhat.com>
Sun, 7 Sep 2014 18:07:49 +0000 (20:07 +0200)
committerEric Blake <eblake@redhat.com>
Wed, 17 Sep 2014 19:24:43 +0000 (13:24 -0600)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit aaaa2d56bd47556b6857ecca33e4b28ab36c8488)

Conflicts:
src/util/virpidfile.c - undo temporary bisection fix in previous patch

src/util/virpidfile.c

index 12ea810f0e615ef6b3b95594c9e07b5b33d2595d..dd29701a757a83bf6eeaf28cc2978aa7516f529f 100644 (file)
@@ -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
@@ -537,34 +540,32 @@ virPidFileConstructPath(bool privileged,
         if (!statedir) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("No statedir specified"));
-            goto error;
+            goto cleanup;
         }
         if (virAsprintf(pidfile, "%s/run/%s.pid", statedir, progname) < 0)
-            goto error;
+            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;
 }