Fix: release reference to ltt_session on error instead of free()
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 Feb 2019 03:05:32 +0000 (22:05 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 Mar 2019 18:41:05 +0000 (14:41 -0400)
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 <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/session.c
src/bin/lttng-sessiond/session.h
src/bin/lttng-sessiond/snapshot.c

index e7967f45ef3bafe3c990dbd0521f60c01dd5b828..5e6488e4f28c67a98fc3bdf9cb1459fedde50fc3 100644 (file)
@@ -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(&ltt_session_list.removal_cond);
+       if (session->published) {
+               ASSERT_LOCKED(ltt_session_list.lock);
+               del_session_list(session);
+               del_session_ht(session);
+               pthread_cond_broadcast(&ltt_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;
index ec03029205163cd5e230337850fed5a88edcad63..6a0da6c164f95a48b15a2e0250611d77a0dcf2ec 100644 (file)
@@ -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 */
index 447806bf4428fd4d8de87b411818b00b5fd5c372..c4c3bf1f8c13d9f0433a57d61461568304a83523 100644 (file)
@@ -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,
This page took 0.027346 seconds and 4 git commands to generate.