Fix: dereference before null check
[lttng-ust.git] / liblttng-ust-ctl / ustctl.c
index 00d9802ee300a1dfc391e08d3f3e9f1cba0e398f..854d8ae391d25c43a2179193c99dc398a9ee7ef4 100644 (file)
@@ -1012,6 +1012,8 @@ chan_error:
 
 void ustctl_destroy_channel(struct ustctl_consumer_channel *chan)
 {
+       (void) ustctl_channel_close_wait_fd(chan);
+       (void) ustctl_channel_close_wakeup_fd(chan);
        chan->chan->ops->channel_destroy(chan->chan);
        free(chan);
 }
@@ -1220,6 +1222,8 @@ void ustctl_destroy_stream(struct ustctl_consumer_stream *stream)
        assert(stream);
        buf = stream->buf;
        consumer_chan = stream->chan;
+       (void) ustctl_stream_close_wait_fd(stream);
+       (void) ustctl_stream_close_wakeup_fd(stream);
        lib_ring_buffer_release_read(buf, consumer_chan->chan->handle);
        free(stream);
 }
@@ -1519,11 +1523,13 @@ int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream,
                uint64_t *timestamp_begin)
 {
        struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
-       struct lttng_ust_lib_ring_buffer *buf = stream->buf;
-       struct lttng_ust_shm_handle *handle = stream->chan->chan->handle;
+       struct lttng_ust_lib_ring_buffer *buf;
+       struct lttng_ust_shm_handle *handle;
 
        if (!stream || !timestamp_begin)
                return -EINVAL;
+       buf = stream->buf;
+       handle = stream->chan->chan->handle;
        client_cb = get_client_cb(buf, handle);
        if (!client_cb)
                return -ENOSYS;
@@ -1534,11 +1540,13 @@ int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream,
        uint64_t *timestamp_end)
 {
        struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
-       struct lttng_ust_lib_ring_buffer *buf = stream->buf;
-       struct lttng_ust_shm_handle *handle = stream->chan->chan->handle;
+       struct lttng_ust_lib_ring_buffer *buf;
+       struct lttng_ust_shm_handle *handle;
 
        if (!stream || !timestamp_end)
                return -EINVAL;
+       buf = stream->buf;
+       handle = stream->chan->chan->handle;
        client_cb = get_client_cb(buf, handle);
        if (!client_cb)
                return -ENOSYS;
@@ -1549,11 +1557,13 @@ int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream,
        uint64_t *events_discarded)
 {
        struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
-       struct lttng_ust_lib_ring_buffer *buf = stream->buf;
-       struct lttng_ust_shm_handle *handle = stream->chan->chan->handle;
+       struct lttng_ust_lib_ring_buffer *buf;
+       struct lttng_ust_shm_handle *handle;
 
        if (!stream || !events_discarded)
                return -EINVAL;
+       buf = stream->buf;
+       handle = stream->chan->chan->handle;
        client_cb = get_client_cb(buf, handle);
        if (!client_cb)
                return -ENOSYS;
@@ -1564,11 +1574,13 @@ int ustctl_get_content_size(struct ustctl_consumer_stream *stream,
        uint64_t *content_size)
 {
        struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
-       struct lttng_ust_lib_ring_buffer *buf = stream->buf;
-       struct lttng_ust_shm_handle *handle = stream->chan->chan->handle;
+       struct lttng_ust_lib_ring_buffer *buf;
+       struct lttng_ust_shm_handle *handle;
 
        if (!stream || !content_size)
                return -EINVAL;
+       buf = stream->buf;
+       handle = stream->chan->chan->handle;
        client_cb = get_client_cb(buf, handle);
        if (!client_cb)
                return -ENOSYS;
@@ -1579,11 +1591,13 @@ int ustctl_get_packet_size(struct ustctl_consumer_stream *stream,
        uint64_t *packet_size)
 {
        struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
-       struct lttng_ust_lib_ring_buffer *buf = stream->buf;
-       struct lttng_ust_shm_handle *handle = stream->chan->chan->handle;
+       struct lttng_ust_lib_ring_buffer *buf;
+       struct lttng_ust_shm_handle *handle;
 
        if (!stream || !packet_size)
                return -EINVAL;
+       buf = stream->buf;
+       handle = stream->chan->chan->handle;
        client_cb = get_client_cb(buf, handle);
        if (!client_cb)
                return -ENOSYS;
@@ -1594,11 +1608,13 @@ int ustctl_get_stream_id(struct ustctl_consumer_stream *stream,
                uint64_t *stream_id)
 {
        struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
-       struct lttng_ust_lib_ring_buffer *buf = stream->buf;
-       struct lttng_ust_shm_handle *handle = stream->chan->chan->handle;
+       struct lttng_ust_lib_ring_buffer *buf;
+       struct lttng_ust_shm_handle *handle;
 
        if (!stream || !stream_id)
                return -EINVAL;
+       buf = stream->buf;
+       handle = stream->chan->chan->handle;
        client_cb = get_client_cb(buf, handle);
        if (!client_cb)
                return -ENOSYS;
@@ -1609,11 +1625,13 @@ int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream,
                uint64_t *ts)
 {
        struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
-       struct lttng_ust_lib_ring_buffer *buf = stream->buf;
-       struct lttng_ust_shm_handle *handle = stream->chan->chan->handle;
+       struct lttng_ust_lib_ring_buffer *buf;
+       struct lttng_ust_shm_handle *handle;
 
        if (!stream || !ts)
                return -EINVAL;
+       buf = stream->buf;
+       handle = stream->chan->chan->handle;
        client_cb = get_client_cb(buf, handle);
        if (!client_cb || !client_cb->current_timestamp)
                return -ENOSYS;
This page took 0.025891 seconds and 4 git commands to generate.