Blame SOURCES/irqbalance-1.5.0-Don-t-leak-socket-fd-on-connection-error.patch

a48aee
From ce71f0cc2255aba072eabb2af26f6cb0e31f8189 Mon Sep 17 00:00:00 2001
a48aee
From: Kairui Song <kasong@redhat.com>
a48aee
Date: Tue, 6 Nov 2018 10:37:15 +0800
a48aee
Subject: Don't leak socket fd on connection error
a48aee
a48aee
Signed-off-by: Kairui Song <kasong@redhat.com>
a48aee
---
a48aee
 irqbalance.c       | 7 ++++---
a48aee
 ui/irqbalance-ui.c | 1 +
a48aee
 2 files changed, 5 insertions(+), 3 deletions(-)
a48aee
a48aee
diff --git a/irqbalance.c b/irqbalance.c
a48aee
index c89c3c0..a77f842 100644
a48aee
--- a/irqbalance.c
a48aee
+++ b/irqbalance.c
a48aee
@@ -389,7 +389,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
a48aee
 		}
a48aee
 		if ((recv_size = recvmsg(sock, &msg, 0)) < 0) {
a48aee
 			log(TO_ALL, LOG_WARNING, "Error while receiving data.\n");
a48aee
-			goto out;
a48aee
+			goto out_close;
a48aee
 		}
a48aee
 		cmsg = CMSG_FIRSTHDR(&msg;;
a48aee
 		if ((cmsg->cmsg_level == SOL_SOCKET) &&
a48aee
@@ -401,7 +401,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
a48aee
 		}
a48aee
 		if (!valid_user) {
a48aee
 			log(TO_ALL, LOG_INFO, "Permission denied for user to connect to socket.\n");
a48aee
-			goto out;
a48aee
+			goto out_close;
a48aee
 		}
a48aee
 
a48aee
 		if (!strncmp(buff, "stats", strlen("stats"))) {
a48aee
@@ -434,7 +434,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
a48aee
 				need_rescan = 1;
a48aee
 				if (!strncmp(irq_string, "NONE", strlen("NONE"))) {
a48aee
 					free(irq_string);
a48aee
-					goto out;
a48aee
+					goto out_close;
a48aee
 				}
a48aee
 				int irq = strtoul(irq_string, &end, 10);
a48aee
 				do {
a48aee
@@ -470,6 +470,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
a48aee
 			free(setup);
a48aee
 		}
a48aee
 
a48aee
+out_close:
a48aee
 		close(sock);
a48aee
 	}
a48aee
 
a48aee
diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c
a48aee
index 99f2ca2..6d4c845 100644
a48aee
--- a/ui/irqbalance-ui.c
a48aee
+++ b/ui/irqbalance-ui.c
a48aee
@@ -62,6 +62,7 @@ int init_connection()
a48aee
 
a48aee
 	if(connect(socket_fd, (struct sockaddr *)&addr,
a48aee
 				sizeof(sa_family_t) + strlen(socket_name) + 1) < 0) {
a48aee
+		close(socket_fd);
a48aee
 		return 0;
a48aee
 	}
a48aee
 
a48aee
-- 
a48aee
2.17.1
a48aee