From: Jérémie Galarneau Date: Mon, 14 Jan 2019 21:36:21 +0000 (-0500) Subject: Fix: dereference on NULL pointer on allocation failure X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=21fa020ee12d44632c5efde063869d542897bdd1 Fix: dereference on NULL pointer on allocation failure Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/agent-thread.c b/src/bin/lttng-sessiond/agent-thread.c index 3ee383389..f7be1ef71 100644 --- a/src/bin/lttng-sessiond/agent-thread.c +++ b/src/bin/lttng-sessiond/agent-thread.c @@ -504,7 +504,7 @@ bool launch_agent_management_thread(void) notifiers = zmalloc(sizeof(*notifiers)); if (!notifiers) { - goto error; + goto error_alloc; } sem_init(¬ifiers->ready, 0, 0); @@ -525,5 +525,6 @@ bool launch_agent_management_thread(void) return true; error: cleanup_agent_management_thread(notifiers); +error_alloc: return false; } diff --git a/src/bin/lttng-sessiond/health.c b/src/bin/lttng-sessiond/health.c index e8c42e4bd..921b45261 100644 --- a/src/bin/lttng-sessiond/health.c +++ b/src/bin/lttng-sessiond/health.c @@ -265,7 +265,7 @@ bool launch_health_management_thread(void) notifiers = zmalloc(sizeof(*notifiers)); if (!notifiers) { - goto error; + goto error_alloc; } sem_init(¬ifiers->ready, 0, 0); @@ -287,5 +287,6 @@ bool launch_health_management_thread(void) return true; error: cleanup_health_management_thread(notifiers); +error_alloc: return false; } diff --git a/src/bin/lttng-sessiond/manage-apps.c b/src/bin/lttng-sessiond/manage-apps.c index 6ef0351fe..f9ec356da 100644 --- a/src/bin/lttng-sessiond/manage-apps.c +++ b/src/bin/lttng-sessiond/manage-apps.c @@ -226,13 +226,12 @@ bool launch_application_management_thread(int apps_cmd_pipe_read_fd) struct thread_notifiers *notifiers = NULL; struct lttng_thread *thread; - quit_pipe = lttng_pipe_open(FD_CLOEXEC); - if (!quit_pipe) { - goto error; - } - notifiers = zmalloc(sizeof(*notifiers)); if (!notifiers) { + goto error_alloc; + } + quit_pipe = lttng_pipe_open(FD_CLOEXEC); + if (!quit_pipe) { goto error; } notifiers->quit_pipe = quit_pipe; @@ -251,5 +250,6 @@ bool launch_application_management_thread(int apps_cmd_pipe_read_fd) return true; error: cleanup_application_management_thread(notifiers); +error_alloc: return false; } diff --git a/src/bin/lttng-sessiond/manage-consumer.c b/src/bin/lttng-sessiond/manage-consumer.c index 47bfe521c..68c7d649b 100644 --- a/src/bin/lttng-sessiond/manage-consumer.c +++ b/src/bin/lttng-sessiond/manage-consumer.c @@ -447,13 +447,13 @@ bool launch_consumer_management_thread(struct consumer_data *consumer_data) struct thread_notifiers *notifiers = NULL; struct lttng_thread *thread; - quit_pipe = lttng_pipe_open(FD_CLOEXEC); - if (!quit_pipe) { - goto error; - } - notifiers = zmalloc(sizeof(*notifiers)); if (!notifiers) { + goto error_alloc; + } + + quit_pipe = lttng_pipe_open(FD_CLOEXEC); + if (!quit_pipe) { goto error; } notifiers->quit_pipe = quit_pipe; @@ -476,5 +476,6 @@ bool launch_consumer_management_thread(struct consumer_data *consumer_data) return true; error: cleanup_consumer_management_thread(notifiers); +error_alloc: return false; } diff --git a/src/bin/lttng-sessiond/manage-kernel.c b/src/bin/lttng-sessiond/manage-kernel.c index 56bc0a93c..34887d7b1 100644 --- a/src/bin/lttng-sessiond/manage-kernel.c +++ b/src/bin/lttng-sessiond/manage-kernel.c @@ -347,13 +347,12 @@ bool launch_kernel_management_thread(int kernel_poll_pipe_read_fd) struct thread_notifiers *notifiers = NULL; struct lttng_thread *thread; - quit_pipe = lttng_pipe_open(FD_CLOEXEC); - if (!quit_pipe) { - goto error; - } - notifiers = zmalloc(sizeof(*notifiers)); if (!notifiers) { + goto error_alloc; + } + quit_pipe = lttng_pipe_open(FD_CLOEXEC); + if (!quit_pipe) { goto error; } notifiers->quit_pipe = quit_pipe; @@ -371,5 +370,6 @@ bool launch_kernel_management_thread(int kernel_poll_pipe_read_fd) return true; error: cleanup_kernel_management_thread(notifiers); +error_alloc: return false; } diff --git a/src/bin/lttng-sessiond/notify-apps.c b/src/bin/lttng-sessiond/notify-apps.c index fee184345..bc7405c7b 100644 --- a/src/bin/lttng-sessiond/notify-apps.c +++ b/src/bin/lttng-sessiond/notify-apps.c @@ -230,7 +230,7 @@ bool launch_application_notification_thread(int apps_cmd_notify_pipe_read_fd) notifiers = zmalloc(sizeof(*notifiers)); if (!notifiers) { - goto error; + goto error_alloc; } notifiers->apps_cmd_notify_pipe_read_fd = apps_cmd_notify_pipe_read_fd; @@ -252,5 +252,6 @@ bool launch_application_notification_thread(int apps_cmd_notify_pipe_read_fd) return true; error: cleanup_application_notification_thread(notifiers); +error_alloc: return false; } diff --git a/src/bin/lttng-sessiond/register.c b/src/bin/lttng-sessiond/register.c index d0a1ff14a..6ce25ad0f 100644 --- a/src/bin/lttng-sessiond/register.c +++ b/src/bin/lttng-sessiond/register.c @@ -400,13 +400,12 @@ struct lttng_thread *launch_application_registration_thread( struct thread_notifiers *notifiers = NULL; struct lttng_thread *thread; - quit_pipe = lttng_pipe_open(FD_CLOEXEC); - if (!quit_pipe) { - goto error; - } - notifiers = zmalloc(sizeof(*notifiers)); if (!notifiers) { + goto error_alloc; + } + quit_pipe = lttng_pipe_open(FD_CLOEXEC); + if (!quit_pipe) { goto error; } notifiers->quit_pipe = quit_pipe; @@ -428,5 +427,6 @@ struct lttng_thread *launch_application_registration_thread( return thread; error: cleanup_application_registration_thread(notifiers); +error_alloc: return NULL; } diff --git a/src/bin/lttng-sessiond/thread.c b/src/bin/lttng-sessiond/thread.c index 7e16b69ed..6eb5e8efb 100644 --- a/src/bin/lttng-sessiond/thread.c +++ b/src/bin/lttng-sessiond/thread.c @@ -88,7 +88,7 @@ struct lttng_thread *lttng_thread_create(const char *name, thread = zmalloc(sizeof(*thread)); if (!thread) { - goto error; + goto error_alloc; } urcu_ref_init(&thread->ref); @@ -127,9 +127,9 @@ error_pthread_create: /* Release list reference. */ lttng_thread_put(thread); pthread_mutex_unlock(&thread_list.lock); -error: /* Release initial reference. */ lttng_thread_put(thread); +error_alloc: return NULL; }