Fix: sessiond: lttng_channel object is not reclaimed
[lttng-tools.git] / src / bin / lttng-sessiond / session.cpp
index 0d19042b594f8edfda6817a866cf6931378a8b4b..14de5468c7979f523cd98d0504e3fed70d54764c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
  *
  * SPDX-License-Identifier: GPL-2.0-only
  *
@@ -331,12 +331,12 @@ end:
 static void ltt_sessions_ht_destroy(void)
 {
        if (ltt_sessions_ht_by_id) {
-               ht_cleanup_push(ltt_sessions_ht_by_id);
+               lttng_ht_destroy(ltt_sessions_ht_by_id);
                ltt_sessions_ht_by_id = NULL;
        }
 
        if (ltt_sessions_ht_by_name) {
-               ht_cleanup_push(ltt_sessions_ht_by_name);
+               lttng_ht_destroy(ltt_sessions_ht_by_name);
                ltt_sessions_ht_by_name = NULL;
        }
 
@@ -398,7 +398,7 @@ end:
 }
 
 /*
- * Remove a ltt_session from the ltt_sessions_ht_by_id/name.
+ * Remove a ltt_session from the ltt_sessions_ht_by_id.
  * If empty, the ltt_sessions_ht_by_id/name HTs are freed.
  * The session list lock must be held.
  */
@@ -415,10 +415,6 @@ static void del_session_ht(struct ltt_session *ls)
        ret = lttng_ht_del(ltt_sessions_ht_by_id, &iter);
        LTTNG_ASSERT(!ret);
 
-       iter.iter.node = &ls->node_by_name.node;
-       ret = lttng_ht_del(ltt_sessions_ht_by_name, &iter);
-       LTTNG_ASSERT(!ret);
-
        if (ltt_sessions_ht_empty()) {
                DBG("Empty ltt_sessions_ht_by_id/name, destroying hast tables");
                ltt_sessions_ht_destroy();
@@ -1065,8 +1061,23 @@ void session_put(struct ltt_session *session)
  */
 void session_destroy(struct ltt_session *session)
 {
+       int ret;
+       struct lttng_ht_iter iter;
+
        LTTNG_ASSERT(!session->destroyed);
        session->destroyed = true;
+
+       /*
+        * Remove immediately from the "session by name" hash table. Only one
+        * session is expected to exist with a given name for at any given time.
+        *
+        * Even if a session still technically exists for a little while longer,
+        * there is no point in performing action on a "destroyed" session.
+        */
+       iter.iter.node = &session->node_by_name.node;
+       ret = lttng_ht_del(ltt_sessions_ht_by_name, &iter);
+       LTTNG_ASSERT(!ret);
+
        session_put(session);
 }
 
@@ -1132,6 +1143,7 @@ struct ltt_session *session_find_by_id(uint64_t id)
        struct lttng_ht_iter iter;
        struct ltt_session *ls;
 
+       ASSERT_RCU_READ_LOCKED();
        ASSERT_LOCKED(ltt_session_list.lock);
 
        if (!ltt_sessions_ht_by_id) {
This page took 0.026349 seconds and 4 git commands to generate.