Fix: ensure kernel context is in a list before trying to delete it
[lttng-tools.git] / src / bin / lttng-sessiond / trace-kernel.c
index 33a9e7e5578daf8454e5ccc97bc3d97d85e7934f..fa207bc67eb1adc8e18a13ba27c583424f6d8a8d 100644 (file)
@@ -15,7 +15,6 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
@@ -162,14 +161,6 @@ struct ltt_kernel_session *trace_kernel_create_session(void)
                goto error;
        }
 
-       /*
-        * The tmp_consumer stays NULL until a set_consumer_uri command is
-        * executed. At this point, the consumer should be nullify until an
-        * enable_consumer command. This assignment is symbolic since we've zmalloc
-        * the struct.
-        */
-       lks->tmp_consumer = NULL;
-
        return lks;
 
 error:
@@ -249,15 +240,38 @@ struct ltt_kernel_context *trace_kernel_create_context(
        if (ctx) {
                memcpy(&kctx->ctx, ctx, sizeof(kctx->ctx));
        }
+error:
+       return kctx;
+}
 
-       CDS_INIT_LIST_HEAD(&kctx->list);
+/*
+ * Allocate and init a kernel context object from an existing kernel context
+ * object.
+ *
+ * Return the allocated object or NULL on error.
+ */
+struct ltt_kernel_context *trace_kernel_copy_context(
+               struct ltt_kernel_context *kctx)
+{
+       struct ltt_kernel_context *kctx_copy;
+
+       assert(kctx);
+       kctx_copy = zmalloc(sizeof(*kctx_copy));
+       if (!kctx_copy) {
+               PERROR("zmalloc ltt_kernel_context");
+               goto error;
+       }
+
+       memcpy(kctx_copy, kctx, sizeof(*kctx_copy));
+       memset(&kctx_copy->list, 0, sizeof(kctx_copy->list));
 
 error:
-       return kctx;
+       return kctx_copy;
 }
 
 /*
  * Allocate and initialize a kernel event. Set name and event type.
+ * We own filter_expression, and filter.
  *
  * Return pointer to structure or NULL.
  */
@@ -327,6 +341,8 @@ struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev,
        return lke;
 
 error:
+       free(filter_expression);
+       free(filter);
        free(lke);
        free(attr);
        return NULL;
@@ -468,7 +484,9 @@ void trace_kernel_destroy_context(struct ltt_kernel_context *ctx)
 {
        assert(ctx);
 
-       cds_list_del(&ctx->list);
+       if (ctx->in_list) {
+               cds_list_del(&ctx->list);
+       }
        free(ctx);
 }
 
@@ -575,8 +593,7 @@ void trace_kernel_destroy_session(struct ltt_kernel_session *session)
        }
 
        /* Wipe consumer output object */
-       consumer_destroy_output(session->consumer);
-       consumer_destroy_output(session->tmp_consumer);
+       consumer_output_put(session->consumer);
 
        free(session);
 }
This page took 0.025159 seconds and 4 git commands to generate.