|
|
9119d9 |
From 6c6f796b74b96ed85a289dc805ba3e39cad2664b Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <6c6f796b74b96ed85a289dc805ba3e39cad2664b@dist-git>
|
|
|
9119d9 |
From: Martin Kletzander <mkletzan@redhat.com>
|
|
|
9119d9 |
Date: Wed, 17 Sep 2014 17:11:02 +0200
|
|
|
9119d9 |
Subject: [PATCH] util: fix potential leak in error codepath
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=927369
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
9119d9 |
(cherry picked from commit aaaa2d56bd47556b6857ecca33e4b28ab36c8488)
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
src/util/virpidfile.c | 19 ++++++++++---------
|
|
|
9119d9 |
1 file changed, 10 insertions(+), 9 deletions(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
|
|
|
9119d9 |
index 19ec103..dd29701 100644
|
|
|
9119d9 |
--- a/src/util/virpidfile.c
|
|
|
9119d9 |
+++ b/src/util/virpidfile.c
|
|
|
9119d9 |
@@ -529,6 +529,9 @@ virPidFileConstructPath(bool privileged,
|
|
|
9119d9 |
const char *progname,
|
|
|
9119d9 |
char **pidfile)
|
|
|
9119d9 |
{
|
|
|
9119d9 |
+ int ret = -1;
|
|
|
9119d9 |
+ char *rundir = NULL;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
if (privileged) {
|
|
|
9119d9 |
/*
|
|
|
9119d9 |
* This is here just to allow calling this function with
|
|
|
9119d9 |
@@ -542,29 +545,27 @@ virPidFileConstructPath(bool privileged,
|
|
|
9119d9 |
if (virAsprintf(pidfile, "%s/run/%s.pid", statedir, progname) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
} else {
|
|
|
9119d9 |
- char *rundir = NULL;
|
|
|
9119d9 |
mode_t old_umask;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(rundir = virGetUserRuntimeDirectory()))
|
|
|
9119d9 |
- goto error;
|
|
|
9119d9 |
+ goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
old_umask = umask(077);
|
|
|
9119d9 |
if (virFileMakePath(rundir) < 0) {
|
|
|
9119d9 |
umask(old_umask);
|
|
|
9119d9 |
- goto error;
|
|
|
9119d9 |
+ goto cleanup;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
umask(old_umask);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0) {
|
|
|
9119d9 |
VIR_FREE(rundir);
|
|
|
9119d9 |
- goto error;
|
|
|
9119d9 |
+ goto cleanup;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- VIR_FREE(rundir);
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- return 0;
|
|
|
9119d9 |
-
|
|
|
9119d9 |
- error:
|
|
|
9119d9 |
- return -1;
|
|
|
9119d9 |
+ ret = 0;
|
|
|
9119d9 |
+ cleanup:
|
|
|
9119d9 |
+ VIR_FREE(rundir);
|
|
|
9119d9 |
+ return ret;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.0
|
|
|
9119d9 |
|