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