Cleanup: Reduce scope of connections in main relayd thread
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.c
index 65ba82c1b99b16bb51991161bc32f42dafcadcae..1a00e9349fb2f04c6052a5222acaf7d927fdd471 100644 (file)
@@ -15,6 +15,7 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <assert.h>
 #include <inttypes.h>
 
@@ -592,6 +593,7 @@ int ust_registry_session_init(struct ust_registry_session **sessionp,
 
 error:
        ust_registry_session_destroy(session);
+       free(session);
 error_alloc:
        return -1;
 }
@@ -606,20 +608,27 @@ void ust_registry_session_destroy(struct ust_registry_session *reg)
        struct lttng_ht_iter iter;
        struct ust_registry_channel *chan;
 
+       if (!reg) {
+               return;
+       }
+
        /* On error, EBUSY can be returned if lock. Code flow error. */
        ret = pthread_mutex_destroy(&reg->lock);
        assert(!ret);
 
-       rcu_read_lock();
-       /* Destroy all event associated with this registry. */
-       cds_lfht_for_each_entry(reg->channels->ht, &iter.iter, chan, node.node) {
-               /* Delete the node from the ht and free it. */
-               ret = lttng_ht_del(reg->channels, &iter);
-               assert(!ret);
-               destroy_channel(chan);
+       if (reg->channels) {
+               rcu_read_lock();
+               /* Destroy all event associated with this registry. */
+               cds_lfht_for_each_entry(reg->channels->ht, &iter.iter, chan,
+                               node.node) {
+                       /* Delete the node from the ht and free it. */
+                       ret = lttng_ht_del(reg->channels, &iter);
+                       assert(!ret);
+                       destroy_channel(chan);
+               }
+               rcu_read_unlock();
+               ht_cleanup_push(reg->channels);
        }
-       rcu_read_unlock();
 
-       ht_cleanup_push(reg->channels);
        free(reg->metadata);
 }
This page took 0.026899 seconds and 4 git commands to generate.