Fix: stream fd leaks on error
[lttng-ust.git] / liblttng-ust / lttng-ust-abi.c
index b35065996815a1cc3c8fd56aac47a6f6471018e6..77bb90db02d24d42ccdf6c996a3d1c82e9266e70 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;
 }
 
@@ -1117,6 +1107,9 @@ int lttng_abi_map_stream(int channel_objd, struct lttng_ust_stream *info,
                info->stream_nr, info->len);
        if (ret)
                goto error_add_stream;
+       /* Take ownership of shm_fd and wakeup_fd. */
+       uargs->stream.shm_fd = -1;
+       uargs->stream.wakeup_fd = -1;
 
        return 0;
 
This page took 0.024244 seconds and 4 git commands to generate.