From: Jérémie Galarneau Date: Tue, 26 Feb 2019 03:05:32 +0000 (-0500) Subject: Fix: release reference to ltt_session on error instead of free() X-Git-Tag: v2.11.0-rc2~65 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=56ca63c0c5a9aab20b11da9cb26de311b57120bd;p=lttng-tools.git Fix: release reference to ltt_session on error instead of free() Since ltt_session objects within the session daemon are now reference counted, it is more appropriate to release a reference on error rather than calling free() directly in session_create(). The session_release() function also performs additional that can be needed in some of the error paths of session_create(). Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c index e7967f45e..5e6488e4f 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.c @@ -444,10 +444,12 @@ void session_release(struct urcu_ref *ref) consumer_output_put(session->consumer); snapshot_destroy(&session->snapshot); - ASSERT_LOCKED(ltt_session_list.lock); - del_session_list(session); - del_session_ht(session); - pthread_cond_broadcast(<t_session_list.removal_cond); + if (session->published) { + ASSERT_LOCKED(ltt_session_list.lock); + del_session_list(session); + del_session_ht(session); + pthread_cond_broadcast(<t_session_list.removal_cond); + } free(session); } @@ -630,6 +632,7 @@ int session_create(char *name, uid_t uid, gid_t gid) * by session id. */ add_session_ht(new_session); + new_session->published = true; session_unlock_list(); /* @@ -643,7 +646,9 @@ int session_create(char *name, uid_t uid, gid_t gid) error: error_asprintf: - free(new_session); + session_lock_list(); + session_put(new_session); + session_unlock_list(); error_malloc: return ret; diff --git a/src/bin/lttng-sessiond/session.h b/src/bin/lttng-sessiond/session.h index ec0302920..6a0da6c16 100644 --- a/src/bin/lttng-sessiond/session.h +++ b/src/bin/lttng-sessiond/session.h @@ -81,6 +81,8 @@ struct ltt_session { pthread_mutex_t lock; struct cds_list_head list; uint64_t id; /* session unique identifier */ + /* Indicates if the session has been added to the session list and ht.*/ + bool published; /* Indicates if a destroy command has been applied to this session. */ bool destroyed; /* UID/GID of the user owning the session */ diff --git a/src/bin/lttng-sessiond/snapshot.c b/src/bin/lttng-sessiond/snapshot.c index 447806bf4..c4c3bf1f8 100644 --- a/src/bin/lttng-sessiond/snapshot.c +++ b/src/bin/lttng-sessiond/snapshot.c @@ -321,7 +321,9 @@ void snapshot_destroy(struct snapshot *obj) struct lttng_ht_iter iter; struct snapshot_output *output; - assert(obj); + if (!obj->output_ht) { + return; + } rcu_read_lock(); cds_lfht_for_each_entry(obj->output_ht->ht, &iter.iter, output,