From: Jérémie Galarneau Date: Sun, 8 Jan 2017 19:29:09 +0000 (-0500) Subject: Fix: reverse channel and metadata cache lock nesting order X-Git-Tag: v2.10.0-rc1~76 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=fb549e7ac25c17c8bfa0f2d407c3802ffe2609fb;p=lttng-tools.git Fix: reverse channel and metadata cache lock nesting order 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 --- diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index 3415cfe92..89dad5917 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -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) {