Fix: leak on UST buffer registry creation error
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 18 Dec 2014 01:45:13 +0000 (20:45 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 5 Jan 2015 20:10:01 +0000 (15:10 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng-sessiond/ust-registry.c

index 891d75f7c000b287a5707e702ef04a972f398ac3..9dbd49bc3fe5a2911e0516324824383f9257908a 100644 (file)
@@ -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(&reg_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;
index 3f4a962c1014de3913f416e25d3ae6f94db1df21..1a00e9349fb2f04c6052a5222acaf7d927fdd471 100644 (file)
@@ -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(&reg->lock);
This page took 0.029406 seconds and 4 git commands to generate.