From 9d8efb0ed1d06ea73d77b8a0539b67d1e0dc501b Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 28 Nov 2013 15:52:25 -0500 Subject: [PATCH] Fix: dereference after null check in UST registry Fix coverity issue 1132896. Signed-off-by: David Goulet --- src/bin/lttng-sessiond/ust-registry.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/bin/lttng-sessiond/ust-registry.c b/src/bin/lttng-sessiond/ust-registry.c index 8c3d08d82..dc494161c 100644 --- a/src/bin/lttng-sessiond/ust-registry.c +++ b/src/bin/lttng-sessiond/ust-registry.c @@ -607,20 +607,25 @@ void ust_registry_session_destroy(struct ust_registry_session *reg) struct lttng_ht_iter iter; struct ust_registry_channel *chan; + assert(reg); + /* On error, EBUSY can be returned if lock. Code flow error. */ ret = pthread_mutex_destroy(®->lock); assert(!ret); - rcu_read_lock(); - /* Destroy all event associated with this registry. */ - cds_lfht_for_each_entry(reg->channels->ht, &iter.iter, chan, node.node) { - /* Delete the node from the ht and free it. */ - ret = lttng_ht_del(reg->channels, &iter); - assert(!ret); - destroy_channel(chan); + if (reg->channels) { + rcu_read_lock(); + /* Destroy all event associated with this registry. */ + cds_lfht_for_each_entry(reg->channels->ht, &iter.iter, chan, + node.node) { + /* Delete the node from the ht and free it. */ + ret = lttng_ht_del(reg->channels, &iter); + assert(!ret); + destroy_channel(chan); + } + rcu_read_unlock(); + ht_cleanup_push(reg->channels); } - rcu_read_unlock(); - ht_cleanup_push(reg->channels); free(reg->metadata); } -- 2.34.1