Fix: Consumer sockets leak on error
authorDavid Goulet <dgoulet@efficios.com>
Mon, 10 Dec 2012 16:20:30 +0000 (11:20 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 10 Dec 2012 16:20:30 +0000 (11:20 -0500)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/common/consumer.c

index ef0d4b7bb3f2edaf073b2215843cf7fc17d9a6e3..5dc1d92b40685598e1c841b8d3128073aeed65ba 100644 (file)
@@ -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;
 }
This page took 0.028424 seconds and 4 git commands to generate.