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-Url: https://git.lttng.org./?a=commitdiff_plain;h=971da06a61170301dc28c2203ef0679c3024e21d;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 eb3ab1a44..1cd70e8c5 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.c @@ -913,6 +913,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 8c13c2dd6..2dcc52b7a 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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;