Permalink
Browse files

Don't leak socket fd on connection error

Signed-off-by: Kairui Song <kasong@redhat.com>
  • Loading branch information...
ryncsn committed Nov 5, 2018
1 parent e783d13 commit f2623176c2997e7803d485084fa5150556caddcf
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 f262317

Please sign in to comment.