render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
a54075
From 0bf4b718fafa22c67f84ffd0b4434a5c7b1bce94 Mon Sep 17 00:00:00 2001
a54075
From: Martin Kletzander <mkletzan@redhat.com>
a54075
Date: Sun, 7 Sep 2014 20:07:49 +0200
a54075
Subject: [PATCH] util: fix potential leak in error codepath
a54075
a54075
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
a54075
(cherry picked from commit aaaa2d56bd47556b6857ecca33e4b28ab36c8488)
a54075
---
a54075
 src/util/virpidfile.c | 19 ++++++++++---------
a54075
 1 file changed, 10 insertions(+), 9 deletions(-)
a54075
a54075
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
a54075
index 19ec103..dd29701 100644
a54075
--- a/src/util/virpidfile.c
a54075
+++ b/src/util/virpidfile.c
a54075
@@ -529,6 +529,9 @@ virPidFileConstructPath(bool privileged,
a54075
                         const char *progname,
a54075
                         char **pidfile)
a54075
 {
a54075
+    int ret = -1;
a54075
+    char *rundir = NULL;
a54075
+
a54075
     if (privileged) {
a54075
         /*
a54075
          * This is here just to allow calling this function with
a54075
@@ -542,29 +545,27 @@ virPidFileConstructPath(bool privileged,
a54075
         if (virAsprintf(pidfile, "%s/run/%s.pid", statedir, progname) < 0)
a54075
             goto cleanup;
a54075
     } else {
a54075
-        char *rundir = NULL;
a54075
         mode_t old_umask;
a54075
 
a54075
         if (!(rundir = virGetUserRuntimeDirectory()))
a54075
-            goto error;
a54075
+            goto cleanup;
a54075
 
a54075
         old_umask = umask(077);
a54075
         if (virFileMakePath(rundir) < 0) {
a54075
             umask(old_umask);
a54075
-            goto error;
a54075
+            goto cleanup;
a54075
         }
a54075
         umask(old_umask);
a54075
 
a54075
         if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0) {
a54075
             VIR_FREE(rundir);
a54075
-            goto error;
a54075
+            goto cleanup;
a54075
         }
a54075
 
a54075
-        VIR_FREE(rundir);
a54075
     }
a54075
 
a54075
-    return 0;
a54075
-
a54075
- error:
a54075
-    return -1;
a54075
+    ret = 0;
a54075
+ cleanup:
a54075
+    VIR_FREE(rundir);
a54075
+    return ret;
a54075
 }