Fix: reverse channel and metadata cache lock nesting order
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 8 Jan 2017 19:29:09 +0000 (14:29 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 8 Jan 2017 19:33:13 +0000 (14:33 -0500)
CID 1368319:  Program hangs  (ORDER_REVERSAL)

The lttng_consumer_channel lock must be nested outside of the
metadata cache lock, as indicated in the structure's comments.

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/consumer/consumer.c

index 3415cfe92872b01d2df95a564dca380db3cc16ce..89dad5917884fd986376107d8189efe8039fbe85 100644 (file)
@@ -2051,11 +2051,11 @@ void consumer_del_metadata_stream(struct lttng_consumer_stream *stream,
        DBG3("Consumer delete metadata stream %d", stream->wait_fd);
 
        pthread_mutex_lock(&consumer_data.lock);
+       pthread_mutex_lock(&stream->chan->lock);
        if (stream->chan->metadata_cache) {
                /* Only applicable to userspace consumers. */
                pthread_mutex_lock(&stream->chan->metadata_cache->lock);
        }
-       pthread_mutex_lock(&stream->chan->lock);
        pthread_mutex_lock(&stream->lock);
 
        /* Remove any reference to that stream. */
@@ -2081,10 +2081,10 @@ void consumer_del_metadata_stream(struct lttng_consumer_stream *stream,
        stream->chan->metadata_stream = NULL;
 
        pthread_mutex_unlock(&stream->lock);
-       pthread_mutex_unlock(&stream->chan->lock);
        if (stream->chan->metadata_cache) {
                pthread_mutex_unlock(&stream->chan->metadata_cache->lock);
        }
+       pthread_mutex_unlock(&stream->chan->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 
        if (free_chan) {
This page took 0.033225 seconds and 5 git commands to generate.