From: Jérémie Galarneau Date: Sat, 15 Nov 2014 05:20:15 +0000 (-0500) Subject: Fix: Ambiguous agent event filter bytecode ownership X-Git-Tag: v2.6.0-rc4~56 X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=0f9981d046e1ce47c392644865f2ad6653d86bfb;p=lttng-tools.git Fix: Ambiguous agent event filter bytecode ownership 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 --- diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.c index ca28f1b78..f2283991a 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.c @@ -910,6 +910,7 @@ void agent_destroy_event(struct agent_event *event) { assert(event); + free(event->filter); free(event); } diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index ccc5ba775..e9427eb24 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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;