Fix: Ambiguous agent event filter bytecode ownership
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 15 Nov 2014 05:20:15 +0000 (00:20 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 16 Nov 2014 11:57:35 +0000 (06:57 -0500)
A shared ownership of the filter bytecode between UST events
and Agent event led to a leak in cmd_enable_event() which was
fixed previously. However, that fix introduced a bug which
passed NULL to the agent event creation function.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/agent.c
src/bin/lttng-sessiond/cmd.c

index eb3ab1a44df9ce89a4541bb69001427cda84e92a..1cd70e8c5f21f82ec2563ff7dd2a6c1766e85ed5 100644 (file)
@@ -913,6 +913,7 @@ void agent_destroy_event(struct agent_event *event)
 {
        assert(event);
 
+       free(event->filter);
        free(event);
 }
 
index 8c13c2dd6aa24414c6a6ee61c3999afe11f68933..2dcc52b7a2aff880bdfbb1c9fc61cb8ece35c27d 100644 (file)
@@ -1604,11 +1604,30 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                        assert(0);
                }
 
-               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;
+               {
+                       struct lttng_filter_bytecode *filter_copy = NULL;
+
+                       if (filter) {
+                               filter_copy = zmalloc(
+                                       sizeof(struct lttng_filter_bytecode)
+                                       + filter->len);
+                               if (!filter_copy) {
+                                       goto error;
+                               }
+
+                               memcpy(filter_copy, filter,
+                                       sizeof(struct lttng_filter_bytecode)
+                                       + filter->len);
+                       }
+
+                       ret = cmd_enable_event(session, &tmp_dom,
+                                       (char *) default_chan_name,
+                                       &uevent, filter_expression, filter_copy,
+                                       NULL, wpipe);
+                       /* We have passed ownership */
+                       filter_expression = NULL;
+               }
+
                if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
                        goto error;
                }
@@ -1616,8 +1635,10 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                /* The wild card * means that everything should be enabled. */
                if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
                        ret = event_agent_enable_all(usess, agt, event, filter);
+                       filter = NULL;
                } else {
                        ret = event_agent_enable(usess, agt, event, filter);
+                       filter = NULL;
                }
                if (ret != LTTNG_OK) {
                        goto error;
This page took 0.030238 seconds and 4 git commands to generate.