Permalink
Browse files

Merge pull request #83 from ryncsn/socket-leak

Don't leak socket fd on connection error
Acked-by: Neil Horman <nhorman@tuxdriver.com>
  • Loading branch information...
nhorman committed Nov 5, 2018
2 parents e783d13 + f262317 commit 926a19c5b66ae1a2440774236e8bd1283666580a
Showing with 5 additions and 3 deletions.
  1. +4 −3 irqbalance.c
  2. +1 −0 ui/irqbalance-ui.c
View
@@ -376,7 +376,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) &&
@@ -388,7 +388,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"))) {
@@ -421,7 +421,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 {
@@ -457,6 +457,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
free(setup);
}
out_close:
close(sock);
}
View
@@ -66,6 +66,7 @@ int init_connection()
memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_UNIX;
if (connect(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
close(socket_fd);
return 0;
}

0 comments on commit 926a19c

Please sign in to comment.