From: Christian Babeux Date: Thu, 8 Nov 2012 19:19:51 +0000 (-0500) Subject: Fix: Teardown of thread_manage_clients on failure of listen/create_poll X-Git-Tag: v2.1.0-rc7~9 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=35df275583d85652cb5132adb9416e32175524e7 Fix: Teardown of thread_manage_clients on failure of listen/create_poll Currently, if the call to lttcomm_listen_unix_sock or create_thread_poll_set fails, the error handling and thread teardown code path is triggered via a jump to an error label. This error handling path closes the sockets that were used and cleanup the poll set. If the listen fails, the poll set will tentatively be cleaned even though it has never been initialized. This patch add 2 labels to differentiate the error handling paths needed in case of failure of lttcomm_listen_unix_sock or create_thread_poll_set. Signed-off-by: Christian Babeux Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 90f11d648..fc52d759b 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -3111,7 +3111,7 @@ static void *thread_manage_clients(void *data) ret = lttcomm_listen_unix_sock(client_sock); if (ret < 0) { - goto error; + goto error_listen; } /* @@ -3120,7 +3120,7 @@ static void *thread_manage_clients(void *data) */ ret = create_thread_poll_set(&events, 2); if (ret < 0) { - goto error; + goto error_create_poll; } /* Add the application registration socket */ @@ -3299,13 +3299,18 @@ static void *thread_manage_clients(void *data) exit: error: - if (err) { - health_error(&health_thread_cmd); - ERR("Health error occurred in %s", __func__); + if (sock >= 0) { + ret = close(sock); + if (ret) { + PERROR("close"); + } } - health_exit(&health_thread_cmd); - DBG("Client thread dying"); + lttng_poll_clean(&events); + clean_command_ctx(&cmd_ctx); + +error_listen: +error_create_poll: unlink(client_unix_sock_path); if (client_sock >= 0) { ret = close(client_sock); @@ -3313,15 +3318,15 @@ error: PERROR("close"); } } - if (sock >= 0) { - ret = close(sock); - if (ret) { - PERROR("close"); - } + + if (err) { + health_error(&health_thread_cmd); + ERR("Health error occurred in %s", __func__); } - lttng_poll_clean(&events); - clean_command_ctx(&cmd_ctx); + health_exit(&health_thread_cmd); + + DBG("Client thread dying"); rcu_unregister_thread(); return NULL;