From: Mathieu Desnoyers Date: Mon, 6 Apr 2015 16:17:20 +0000 (-0400) Subject: Fix: ownership of filter and filter_expression X-Git-Tag: v2.7.0-rc1~47 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a969e1019813f1e2354fe57c8393f6268d943414;p=lttng-tools.git Fix: ownership of filter and filter_expression Applies to the kernel wildcard feature. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 95e371d7b..a6ce344a4 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1512,6 +1512,9 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, event->type = LTTNG_EVENT_TRACEPOINT; /* Hack */ ret = event_kernel_enable_event(kchan, event, filter_expression, filter); + /* We have passed ownership */ + filter_expression = NULL; + filter = NULL; if (ret != LTTNG_OK) { if (channel_created) { /* Let's not leak a useless channel. */ @@ -1537,6 +1540,9 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, case LTTNG_EVENT_TRACEPOINT: ret = event_kernel_enable_event(kchan, event, filter_expression, filter); + /* We have passed ownership */ + filter_expression = NULL; + filter = NULL; if (ret != LTTNG_OK) { if (channel_created) { /* Let's not leak a useless channel. */ @@ -1548,6 +1554,9 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, case LTTNG_EVENT_SYSCALL: ret = event_kernel_enable_event(kchan, event, filter_expression, filter); + /* We have passed ownership */ + filter_expression = NULL; + filter = NULL; if (ret != LTTNG_OK) { goto error; } diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index 32efcdbf2..bedaa2e2f 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -143,6 +143,9 @@ int event_kernel_enable_event(struct ltt_kernel_channel *kchan, if (kevent == NULL) { ret = kernel_create_event(event, kchan, filter_expression, filter); + /* We have passed ownership */ + filter_expression = NULL; + filter = NULL; if (ret < 0) { switch (-ret) { case EEXIST: @@ -171,6 +174,8 @@ int event_kernel_enable_event(struct ltt_kernel_channel *kchan, ret = LTTNG_OK; end: + free(filter_expression); + free(filter); return ret; } diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 45d958546..570747f18 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -187,6 +187,7 @@ int kernel_create_event(struct lttng_event *ev, assert(ev); assert(channel); + /* We pass ownership of filter_expression and filter */ event = trace_kernel_create_event(ev, filter_expression, filter); if (event == NULL) { diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index 33a9e7e55..b86bdfe60 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -258,6 +258,7 @@ error: /* * Allocate and initialize a kernel event. Set name and event type. + * We own filter_expression, and filter. * * Return pointer to structure or NULL. */ @@ -327,6 +328,8 @@ struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev, return lke; error: + free(filter_expression); + free(filter); free(lke); free(attr); return NULL;