From 286c991af026bfd127e1de5f97976ff8b291721e Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 17 Dec 2014 20:45:13 -0500 Subject: [PATCH] Fix: leak on UST buffer registry creation error MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/ust-app.c | 21 ++++++++++++++++++--- src/bin/lttng-sessiond/ust-registry.c | 4 +++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 891d75f7c..9dbd49bc3 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -1732,7 +1732,6 @@ static int setup_buffer_reg_pid(struct ust_app_session *ua_sess, if (ret < 0) { goto error; } - buffer_reg_pid_add(reg_pid); } else { goto end; } @@ -1745,9 +1744,18 @@ static int setup_buffer_reg_pid(struct ust_app_session *ua_sess, app->byte_order, app->version.major, app->version.minor); if (ret < 0) { + /* + * reg_pid->registry->reg.ust is NULL upon error, so we need to + * destroy the buffer registry, because it is always expected + * that if the buffer registry can be found, its ust registry is + * non-NULL. + */ + buffer_reg_pid_destroy(reg_pid); goto error; } + buffer_reg_pid_add(reg_pid); + DBG3("UST app buffer registry per PID created successfully"); end: @@ -1788,7 +1796,6 @@ static int setup_buffer_reg_uid(struct ltt_ust_session *usess, if (ret < 0) { goto error; } - buffer_reg_uid_add(reg_uid); } else { goto end; } @@ -1801,13 +1808,21 @@ static int setup_buffer_reg_uid(struct ltt_ust_session *usess, app->byte_order, app->version.major, app->version.minor); if (ret < 0) { + /* + * reg_uid->registry->reg.ust is NULL upon error, so we need to + * destroy the buffer registry, because it is always expected + * that if the buffer registry can be found, its ust registry is + * non-NULL. + */ + buffer_reg_uid_destroy(reg_uid, NULL); goto error; } /* Add node to teardown list of the session. */ cds_list_add(®_uid->lnode, &usess->buffer_reg_uid_list); - DBG3("UST app buffer registry per UID created successfully"); + buffer_reg_uid_add(reg_uid); + DBG3("UST app buffer registry per UID created successfully"); end: if (regp) { *regp = reg_uid; diff --git a/src/bin/lttng-sessiond/ust-registry.c b/src/bin/lttng-sessiond/ust-registry.c index 3f4a962c1..1a00e9349 100644 --- a/src/bin/lttng-sessiond/ust-registry.c +++ b/src/bin/lttng-sessiond/ust-registry.c @@ -608,7 +608,9 @@ void ust_registry_session_destroy(struct ust_registry_session *reg) struct lttng_ht_iter iter; struct ust_registry_channel *chan; - assert(reg); + if (!reg) { + return; + } /* On error, EBUSY can be returned if lock. Code flow error. */ ret = pthread_mutex_destroy(®->lock); -- 2.34.1