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>
Wed, 18 May 2022 14:23:05 +0000 (10:23 -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.h
src/common/actions/path.c
src/common/error-query.c

index 608f144c2b5afa5ec784e9e0fce6f15dd7ec09fc..9f7eaaaa1d3ac6c9dbc4c1f076767937c237ad97 100644 (file)
@@ -23,10 +23,9 @@ struct lttng_action_path {
        struct lttng_dynamic_array indexes;
 };
 
-/* Assumes that 'dst' is uninitialized. */
 LTTNG_HIDDEN
 int lttng_action_path_copy(const struct lttng_action_path *src,
-               struct lttng_action_path *dst);
+               struct lttng_action_path **dst);
 
 LTTNG_HIDDEN
 ssize_t lttng_action_path_create_from_payload(
index 4ee649928f646cee1de22306f71e690fc1bac9fa..250b5e905f4df7d751eecafc7b99c9ceb3a52af2 100644 (file)
@@ -97,32 +97,25 @@ end:
 
 LTTNG_HIDDEN
 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;
 
        assert(src);
        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 2eb1c971715902767e6550c2971d7026c346c6b5..298809711c1d0c511ef137da7d027bdacc7f2f5e 100644 (file)
@@ -47,7 +47,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 {
@@ -246,15 +246,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
@@ -692,7 +722,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;
        }
@@ -747,7 +777,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);
 }
 
 LTTNG_HIDDEN
This page took 0.031385 seconds and 4 git commands to generate.