Fix: action-executor: leak of `work_item::subitems` field
[lttng-tools.git] / src / bin / lttng-sessiond / action-executor.c
index 79c8677143ea3a829cb0a0581c3f2e513de0db33..853146d3b8b3bb6f77c3788cecfb2fa280f0409a 100644 (file)
@@ -730,6 +730,7 @@ static void action_work_item_destroy(struct action_work_item *work_item)
        lttng_evaluation_destroy(work_item->evaluation);
        notification_client_list_put(work_item->client_list);
        lttng_dynamic_array_reset(work_item->subitems);
+       free(work_item->subitems);
        free(work_item);
 }
 
@@ -1076,17 +1077,26 @@ static int add_action_to_subitem_array(struct lttng_action *action,
         * simplicity and consistency.
         */
        if (session_name != NULL) {
-               struct ltt_session *session = NULL;
+               uint64_t session_id;
 
-               session_lock_list();
-               session = session_find_by_name(session_name);
-               if (session) {
+               /*
+                * Instantaneous sampling of the session id if present.
+                *
+                * This method is preferred over `sessiond_find_by_name` then
+                * fetching the session'd id since `sessiond_find_by_name`
+                * requires the session list lock to be taken.
+                *
+                * Taking the session list lock can lead to a deadlock
+                * between the action executor and the notification thread
+                * (caller of add_action_to_subitem_array). It is okay if the
+                * session state changes between the enqueuing time and the
+                * execution time. The execution context is validated at
+                * execution time.
+                */
+               if (sample_session_id_by_name(session_name, &session_id)) {
                        LTTNG_OPTIONAL_SET(&subitem.context.session_id,
-                                       session->id);
-                       session_put(session);
+                                       session_id);
                }
-
-               session_unlock_list();
        }
 
        /* Get a reference to the action. */
This page took 0.023545 seconds and 4 git commands to generate.