From e524139ee8ca53cdae9b36d69013ba160a3d583b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 30 Oct 2019 15:35:28 -0400 Subject: [PATCH] Fix: consumerd: crash occurs when taking snapshot of ust channel MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Commit 8e1ef46e8 added an acquisition of the metadata_stream's lock during consumer_metadata_cache_flushed() as stream attributes are used. However, when this function is called, the metadata channel's stream can already be NULL, as indicated by the function's comments. Check if the stream is NULL before attempting to acquire its lock. Signed-off-by: Jérémie Galarneau --- src/common/consumer/consumer-metadata-cache.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/common/consumer/consumer-metadata-cache.c b/src/common/consumer/consumer-metadata-cache.c index 5eee40142..3fffe5339 100644 --- a/src/common/consumer/consumer-metadata-cache.c +++ b/src/common/consumer/consumer-metadata-cache.c @@ -274,16 +274,19 @@ int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel, } pthread_mutex_lock(&channel->timer_lock); metadata_stream = channel->metadata_stream; - pthread_mutex_lock(&metadata_stream->lock); - pthread_mutex_lock(&channel->metadata_cache->lock); - if (!metadata_stream) { /* * Having no metadata stream means the channel is being destroyed so there * is no cache to flush anymore. */ ret = 0; - } else if (metadata_stream->ust_metadata_pushed >= offset) { + goto end_unlock_channel; + } + + pthread_mutex_lock(&metadata_stream->lock); + pthread_mutex_lock(&channel->metadata_cache->lock); + + if (metadata_stream->ust_metadata_pushed >= offset) { ret = 0; } else if (channel->metadata_stream->endpoint_status != CONSUMER_ENDPOINT_ACTIVE) { @@ -296,6 +299,7 @@ int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel, pthread_mutex_unlock(&channel->metadata_cache->lock); pthread_mutex_unlock(&metadata_stream->lock); +end_unlock_channel: pthread_mutex_unlock(&channel->timer_lock); if (!timer) { pthread_mutex_unlock(&channel->lock); -- 2.34.1