Fix: channel leak on error
[lttng-ust.git] / liblttng-ust / lttng-ust-abi.c
index a024b616fe5198be022ebe6858ae6653556327a6..b5c305a951cc23e6a290401ce2b5c03b894e1d3c 100644 (file)
@@ -453,6 +453,7 @@ static const struct lttng_ust_objd_ops lttng_ops = {
        .cmd = lttng_cmd,
 };
 
+static
 int lttng_abi_map_channel(int session_objd,
                struct lttng_ust_channel *ust_chan,
                union ust_args *uargs,
@@ -497,6 +498,10 @@ int lttng_abi_map_channel(int session_objd,
                goto handle_error;
        }
 
+       /* Ownership of chan_data and wakeup_fd taken by channel handle. */
+       uargs->channel.chan_data = NULL;
+       uargs->channel.wakeup_fd = -1;
+
        chan = shmp(channel_handle, channel_handle->chan);
        assert(chan);
        chan->handle = channel_handle;
@@ -580,24 +585,9 @@ alloc_error:
        channel_destroy(chan, channel_handle, 0);
        return ret;
 
-       /*
-        * error path before channel creation (owning chan_data and
-        * wakeup_fd).
-        */
 handle_error:
 active:
 invalid:
-       {
-               int close_ret;
-
-               lttng_ust_lock_fd_tracker();
-               close_ret = close(wakeup_fd);
-               lttng_ust_unlock_fd_tracker();
-               if (close_ret) {
-                       PERROR("close");
-               }
-       }
-       free(chan_data);
        return ret;
 }
 
@@ -816,10 +806,10 @@ int lttng_ust_event_notifier_group_create_error_counter(int event_notifier_group
                return -EINVAL;
 
        switch (error_counter_conf->bitness) {
-       case LTTNG_UST_COUNTER_BITNESS_64BITS:
+       case LTTNG_UST_COUNTER_BITNESS_64:
                counter_transport_name = "counter-per-cpu-64-modular";
                break;
-       case LTTNG_UST_COUNTER_BITNESS_32BITS:
+       case LTTNG_UST_COUNTER_BITNESS_32:
                counter_transport_name = "counter-per-cpu-32-modular";
                break;
        default:
@@ -846,8 +836,16 @@ int lttng_ust_event_notifier_group_create_error_counter(int event_notifier_group
                goto create_error;
        }
 
-       event_notifier_group->error_counter = counter;
        event_notifier_group->error_counter_len = counter_len;
+       /*
+        * store-release to publish error counter matches load-acquire
+        * in record_error. Ensures the counter is created and the
+        * error_counter_len is set before they are used.
+        * Currently a full memory barrier is used, which could be
+        * turned into acquire-release barriers.
+        */
+       cmm_smp_mb();
+       CMM_STORE_SHARED(event_notifier_group->error_counter, counter);
 
        counter->objd = counter_objd;
        counter->event_notifier_group = event_notifier_group;   /* owner */
This page took 0.023696 seconds and 4 git commands to generate.