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 12:23:00 +0000 (07:23 -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 ca28f1b7801bd8ac8693bff35f239a4d3bc12e63..f2283991a029ce954f794cab9d8ee3251074f690 100644 (file)
@@ -910,6 +910,7 @@ void agent_destroy_event(struct agent_event *event)
 {
        assert(event);
 
+       free(event->filter);
        free(event);
 }
 
index ccc5ba77533fea83ffdf3b93b8f953f7cc344ad2..e9427eb249cfc5e9af9add223160947dfcd5875d 100644 (file)
@@ -1592,11 +1592,30 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                        default_chan_name = DEFAULT_JUL_CHANNEL_NAME;
                }
 
-               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;
                }
@@ -1604,8 +1623,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.048821 seconds and 4 git commands to generate.