From: David Goulet Date: Mon, 10 Dec 2012 16:20:30 +0000 (-0500) Subject: Fix: Consumer sockets leak on error X-Git-Tag: v2.1.0~73 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d96f09c69037dc2437ff85d8311257b87aee38d3;p=lttng-tools.git Fix: Consumer sockets leak on error Signed-off-by: David Goulet --- diff --git a/src/common/consumer.c b/src/common/consumer.c index ef0d4b7bb..5dc1d92b4 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -2454,7 +2454,7 @@ end: */ void *consumer_thread_sessiond_poll(void *data) { - int sock, client_socket, ret; + int sock = -1, client_socket, ret; /* * structure to poll for incoming data on communication socket avoids * making blocking sockets. @@ -2514,6 +2514,13 @@ void *consumer_thread_sessiond_poll(void *data) goto end; } + /* This socket is not useful anymore. */ + ret = close(client_socket); + if (ret < 0) { + PERROR("close client_socket"); + } + client_socket = -1; + /* update the polling structure to poll on the established socket */ consumer_sockpoll[1].fd = sock; consumer_sockpoll[1].events = POLLIN | POLLPRI; @@ -2557,6 +2564,20 @@ end: */ notify_thread_pipe(ctx->consumer_data_pipe[1]); + /* Cleaning up possibly open sockets. */ + if (sock >= 0) { + ret = close(sock); + if (ret < 0) { + PERROR("close sock sessiond poll"); + } + } + if (client_socket >= 0) { + ret = close(sock); + if (ret < 0) { + PERROR("close client_socket sessiond poll"); + } + } + rcu_unregister_thread(); return NULL; }