Fix: action error query: leak of action path
[lttng-tools.git] / src / common / actions / path.c
index 7f4955475aa9775f9001e9a34aebca0e5b864874..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;
 }
 
@@ -143,6 +136,13 @@ ssize_t lttng_action_path_create_from_payload(
 
        header = (typeof(header)) header_view.buffer.data;
        consumed_size += header_view.buffer.size;
+
+       /*
+        * An action path of size 0 can exist and represents a trigger with a
+        * single non-list action. Handle it differently since a payload view of
+        * size 0 is considered invalid.
+        */
+       if (header->index_count != 0)
        {
                const struct lttng_payload_view indexes_view =
                                lttng_payload_view_from_view(view,
@@ -161,6 +161,11 @@ ssize_t lttng_action_path_create_from_payload(
                if (!action_path) {
                        goto end;
                }
+       } else {
+               action_path = lttng_action_path_create(NULL, 0);
+               if (!action_path) {
+                       goto end;
+               }
        }
 
        ret = consumed_size;
This page took 0.02752 seconds and 4 git commands to generate.