Fix: filter bytecode and string memory leak on error
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 13 Nov 2014 22:18:16 +0000 (17:18 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 16 Nov 2014 12:22:53 +0000 (07:22 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/event.c
src/bin/lttng-sessiond/kernel.c
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/trace-ust.c

index d40b58c365be01609300faa1eb77ce2f3063a313..ccc5ba77533fea83ffdf3b93b8f953f7cc344ad2 100644 (file)
@@ -1384,6 +1384,7 @@ end:
 
 /*
  * Command LTTNG_ENABLE_EVENT processed by the client thread.
+ * We own filter, exclusion, and filter_expression.
  */
 int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                char *channel_name, struct lttng_event *event,
@@ -1535,6 +1536,10 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                /* At this point, the session and channel exist on the tracer */
                ret = event_ust_enable_tracepoint(usess, uchan, event,
                                filter_expression, filter, exclusion);
+               /* We have passed ownership */
+               filter_expression = NULL;
+               filter = NULL;
+               exclusion = NULL;
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1589,6 +1594,9 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
 
                ret = cmd_enable_event(session, &tmp_dom, (char *) default_chan_name,
                        &uevent, filter_expression, filter, NULL, wpipe);
+               /* We have passed ownership */
+               filter_expression = NULL;
+               filter = NULL;
                if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
                        goto error;
                }
@@ -1618,6 +1626,9 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
        ret = LTTNG_OK;
 
 error:
+       free(filter_expression);
+       free(filter);
+       free(exclusion);
        rcu_read_unlock();
        return ret;
 }
index 099cbd18db8ea42d767951f094df5dfd81856fbe..a7d437e8a2cc6cdd43c2b5ff97129e150e2d12de 100644 (file)
@@ -180,6 +180,7 @@ int event_kernel_disable_all(struct ltt_kernel_channel *kchan)
 
 /*
  * Enable kernel tracepoint event for a channel from the kernel session.
+ * We own filter_expression and filter.
  */
 int event_kernel_enable_tracepoint(struct ltt_kernel_channel *kchan,
                struct lttng_event *event)
@@ -407,6 +408,7 @@ error:
 
 /*
  * Enable UST tracepoint event for a channel from a UST session.
+ * We own filter_expression, filter, and exclusion.
  */
 int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan, struct lttng_event *event,
@@ -428,6 +430,10 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
        if (uevent == NULL) {
                uevent = trace_ust_create_event(event, filter_expression,
                        filter, exclusion);
+               /* We have passed ownership */
+               filter_expression = NULL;
+               filter = NULL;
+               exclusion = NULL;
                if (uevent == NULL) {
                        ret = LTTNG_ERR_UST_ENABLE_FAIL;
                        goto error;
@@ -475,6 +481,9 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
 
 end:
        rcu_read_unlock();
+       free(filter_expression);
+       free(filter);
+       free(exclusion);
        return ret;
 
 error:
@@ -490,6 +499,9 @@ error:
                trace_ust_destroy_event(uevent);
        }
        rcu_read_unlock();
+       free(filter_expression);
+       free(filter);
+       free(exclusion);
        return ret;
 }
 
index 00bfbbc2be5400d460e2c7dd7c273335f7d444b4..a9151f4d6ffae2a4b56f7ea652b4058b408a37b5 100644 (file)
@@ -173,6 +173,7 @@ error:
 /*
  * Create a kernel event, enable it to the kernel tracer and add it to the
  * channel event list of the kernel session.
+ * We own filter_expression and filter.
  */
 int kernel_create_event(struct lttng_event *ev,
                struct ltt_kernel_channel *channel)
index 977f131c0c0db6a094b85620b826fe15e4114bb1..cec2cd0830d3bef9c2f1dcc4e27838de2a77ee07 100644 (file)
@@ -3212,12 +3212,14 @@ skip_domain:
 
                        if (bytecode_len > LTTNG_FILTER_MAX_LEN) {
                                ret = LTTNG_ERR_FILTER_INVAL;
+                               free(filter_expression);
                                free(exclusion);
                                goto error;
                        }
 
                        bytecode = zmalloc(bytecode_len);
                        if (!bytecode) {
+                               free(filter_expression);
                                free(exclusion);
                                ret = LTTNG_ERR_FILTER_NOMEM;
                                goto error;
@@ -3229,6 +3231,7 @@ skip_domain:
                        if (ret <= 0) {
                                DBG("Nothing recv() from client car len data... continuing");
                                *sock_error = 1;
+                               free(filter_expression);
                                free(bytecode);
                                free(exclusion);
                                ret = LTTNG_ERR_FILTER_INVAL;
@@ -3236,6 +3239,7 @@ skip_domain:
                        }
 
                        if ((bytecode->len + sizeof(*bytecode)) != bytecode_len) {
+                               free(filter_expression);
                                free(bytecode);
                                free(exclusion);
                                ret = LTTNG_ERR_FILTER_INVAL;
index a804fb6b890570e924b0cb54187437598febbbe7..999f0dfc21e75f4e988476be894adcff3e33f4bc 100644 (file)
@@ -365,6 +365,7 @@ error:
 
 /*
  * Allocate and initialize a ust event. Set name and event type.
+ * We own filter_expression, filter, and exclusion.
  *
  * Return pointer to structure or NULL.
  */
@@ -445,6 +446,9 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
 error_free_event:
        free(lue);
 error:
+       free(filter_expression);
+       free(filter);
+       free(exclusion);
        return NULL;
 }
 
This page took 0.031464 seconds and 4 git commands to generate.