[PATCH 36/74] Handle cleanup of locks properly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

restorecond has a leak which this patch fixes.
   This patch looks good to me. acked.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlJpLVsACgkQrlYvE4MpobMgqQCfTl70Fex73ucohJBQokMvKaZP
aV8AoM4Cu3rCbvbyKVArZBWJM+j1Qoqu
=5CDU
-----END PGP SIGNATURE-----
>From 95604c49d8e7fd04dc649dca95fa91baafaec734 Mon Sep 17 00:00:00 2001
From: Dan Walsh <dwalsh@xxxxxxxxxx>
Date: Wed, 9 Oct 2013 17:37:42 -0400
Subject: [PATCH 36/74] Handle cleanup of locks properly

---
 policycoreutils/restorecond/user.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/policycoreutils/restorecond/user.c b/policycoreutils/restorecond/user.c
index 00a646f..2c28676 100644
--- a/policycoreutils/restorecond/user.c
+++ b/policycoreutils/restorecond/user.c
@@ -54,6 +54,7 @@ static const char *PATH="/org/selinux/Restorecond";
 static const char *INTERFACE="org.selinux.RestorecondIface";
 static const char *RULE="type='signal',interface='org.selinux.RestorecondIface'";
 
+static int local_lock_fd = -1;
 
 static DBusHandlerResult
 signal_filter (DBusConnection *connection  __attribute__ ((__unused__)), DBusMessage *message, void *user_data)
@@ -201,17 +202,18 @@ static int local_server() {
 			perror("asprintf");
 		return -1;
 	}
-	int fd = open(ptr, O_CREAT | O_WRONLY | O_NOFOLLOW | O_CLOEXEC, S_IRUSR | S_IWUSR);
+	local_lock_fd = open(ptr, O_CREAT | O_WRONLY | O_NOFOLLOW | O_CLOEXEC, S_IRUSR | S_IWUSR);
 	if (debug_mode)
 		g_warning ("Lock file: %s", ptr);
 
 	free(ptr);
-	if (fd < 0) {
+	if (local_lock_fd < 0) {
 		if (debug_mode)
 			perror("open");
 		return -1;
 	}
-	if (flock(fd, LOCK_EX | LOCK_NB) < 0) {
+	if (flock(local_lock_fd, LOCK_EX | LOCK_NB) < 0) {
+		close(local_lock_fd);
 		if (debug_mode)
 			perror("flock");
 		return -1;
@@ -226,6 +228,12 @@ static int local_server() {
 	return 0;
 }
 
+static void end_local_server(void) {
+	if (local_lock_fd >= 0)
+		close(local_lock_fd);
+	local_lock_fd = -1;
+}
+
 int server(int master_fd, const char *watch_file) {
     GMainLoop *loop;
 
@@ -253,6 +261,7 @@ int server(int master_fd, const char *watch_file) {
     g_main_loop_run (loop);
 
 end:
+    end_local_server();
     g_main_loop_unref (loop);
     return 0;
 }
-- 
1.8.3.1


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux