Fix: action error query: leak of action path
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 15 Apr 2022 03:21:27 +0000 (23:21 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 15 Apr 2022 03:46:04 +0000 (23:46 -0400)
==1429021==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7fe305f031b2 in __interceptor_realloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x559f1b022238 in lttng_dynamic_buffer_set_capacity(lttng_dynamic_buffer*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:159
    #2 0x559f1b021d9f in lttng_dynamic_buffer_append(lttng_dynamic_buffer*, void const*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:52
    #3 0x559f1b02144a in lttng_dynamic_array_add_element(lttng_dynamic_array*, void const*) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-array.cpp:58
    #4 0x559f1b07d07b in lttng_action_path_copy(lttng_action_path const*, lttng_action_path*) actions/path.cpp:116
    #5 0x559f1b02383f in lttng_error_query_action_create /home/jgalar/EfficiOS/src/lttng-tools/src/common/error-query.cpp:232
    #6 0x559f1b02760e in lttng_error_query_create_from_payload(lttng_payload_view*, lttng_error_query**) /home/jgalar/EfficiOS/src/lttng-tools/src/common/error-query.cpp:911
    #7 0x559f1af5c361 in receive_lttng_error_query /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:740
    #8 0x559f1af64eba in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2336
    #9 0x559f1af67378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624
    #10 0x559f1af50642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68
    #11 0x7fe3055225c1 in start_thread (/usr/lib/libc.so.6+0x8d5c1)

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I7a6f7d2a9746124581eebf30877466f16db67a6b

include/lttng/action/path-internal.hpp
src/common/actions/path.cpp
src/common/error-query.cpp

index 9b9a4d10d152f72b7eb1340583a13293fdadee0d..f07776b9bb251790c5a741ed56a1fa01ce3ea562 100644 (file)
@@ -19,9 +19,8 @@ struct lttng_action_path {
        struct lttng_dynamic_array indexes;
 };
 
-/* Assumes that 'dst' is uninitialized. */
 int lttng_action_path_copy(const struct lttng_action_path *src,
-               struct lttng_action_path *dst);
+               struct lttng_action_path **dst);
 
 ssize_t lttng_action_path_create_from_payload(
                struct lttng_payload_view *view,
index 4728485177a209a5c5aa7ddfc95033c04c3cd597..41fb92e27bddfc2e599a72807e9de7feefaeb216 100644 (file)
@@ -98,32 +98,25 @@ end:
 }
 
 int lttng_action_path_copy(const struct lttng_action_path *src,
-               struct lttng_action_path *dst)
+               struct lttng_action_path **dst)
 {
        int ret;
-       size_t i, src_count;
+       struct lttng_action_path *new_path;
 
        LTTNG_ASSERT(src);
        LTTNG_ASSERT(dst);
 
-       lttng_dynamic_array_init(&dst->indexes, sizeof(uint64_t), NULL);
-       src_count = lttng_dynamic_array_get_count(&src->indexes);
-
-       for (i = 0; i < src_count; i++) {
-               const void *index = lttng_dynamic_array_get_element(
-                               &src->indexes, i);
-
-               ret = lttng_dynamic_array_add_element(&dst->indexes, index);
-               if (ret) {
-                       goto error;
-               }
+       new_path = lttng_action_path_create(
+                       (uint64_t *) lttng_dynamic_array_get_element(
+                               &src->indexes, 0), 
+                       lttng_dynamic_array_get_count(&src->indexes));
+       if (!new_path) {
+               ret = -1;
+       } else {
+               ret = 0;
+               *dst = new_path;
        }
 
-       ret = 0;
-       goto end;
-error:
-       lttng_dynamic_array_reset(&dst->indexes);
-end:
        return ret;
 }
 
index 31de0ee5e764c7d1b0ea98a784668afaedbdc304..8c1bb95414feb84e1300a5570c47cd9ce0c83501 100644 (file)
@@ -58,7 +58,7 @@ struct lttng_error_query_action {
        struct lttng_error_query parent;
        /* Mutable only because of the reference count. */
        struct lttng_trigger *trigger;
-       struct lttng_action_path action_path;
+       struct lttng_action_path *action_path;
 };
 
 struct lttng_error_query_result_comm {
@@ -248,15 +248,45 @@ end:
 
 void lttng_error_query_destroy(struct lttng_error_query *query)
 {
-       struct lttng_error_query_trigger *trigger_query;
-
        if (!query) {
                return;
        }
 
-       trigger_query = container_of(query, typeof(*trigger_query), parent);
-       lttng_trigger_put(trigger_query->trigger);
-       free(trigger_query);
+       switch (query->target_type) {
+       case LTTNG_ERROR_QUERY_TARGET_TYPE_TRIGGER:
+       {
+               struct lttng_error_query_trigger *trigger_query =
+                               container_of(query, typeof(*trigger_query),
+                                       parent);
+
+               lttng_trigger_put(trigger_query->trigger);
+               free(trigger_query);
+               break;
+       }
+       case LTTNG_ERROR_QUERY_TARGET_TYPE_CONDITION:
+       {
+               struct lttng_error_query_condition *condition_query =
+                               container_of(query, typeof(*condition_query),
+                                       parent);
+
+               lttng_trigger_put(condition_query->trigger);
+               free(condition_query);
+               break;
+       }
+       case LTTNG_ERROR_QUERY_TARGET_TYPE_ACTION:
+       {
+               struct lttng_error_query_action *action_query =
+                               container_of(query, typeof(*action_query),
+                                       parent);
+
+               lttng_trigger_put(action_query->trigger);
+               lttng_action_path_destroy(action_query->action_path);
+               free(action_query);
+               break;
+       }
+       default:
+               abort();
+       }
 }
 
 static
@@ -688,7 +718,7 @@ int lttng_error_query_action_serialize(const struct lttng_error_query *query,
                goto end;
        }
 
-       ret = lttng_action_path_serialize(&query_action->action_path, payload);
+       ret = lttng_action_path_serialize(query_action->action_path, payload);
        if (ret) {
                goto end;
        }
@@ -738,7 +768,7 @@ struct lttng_action *lttng_error_query_action_borrow_action_target(
                        container_of(query, typeof(*query_action), parent);
 
        return get_trigger_action_from_path(
-                       trigger, &query_action->action_path);
+                       trigger, query_action->action_path);
 }
 
 int lttng_error_query_serialize(const struct lttng_error_query *query,
This page took 0.030777 seconds and 5 git commands to generate.