From: Mathieu Desnoyers Date: Wed, 3 Mar 2021 15:22:38 +0000 (-0500) Subject: Fix: memory leaks on event notifier destroy X-Git-Tag: v2.13.0-rc1~40 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3ef5cc037506f5bce971bd66ef2f77310eca6650;p=lttng-modules.git Fix: memory leaks on event notifier destroy Both filter runtime and event enabler ref objects are owned by the event notifier, but are not freed upon destruction of the event notifier object, thus leaking memory. Signed-off-by: Mathieu Desnoyers Change-Id: I511569f56a38f670549a93cb6179b77861245712 --- diff --git a/include/lttng/events.h b/include/lttng/events.h index e6572680..6aa880f8 100644 --- a/include/lttng/events.h +++ b/include/lttng/events.h @@ -987,6 +987,7 @@ void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, struct list_head *instance_bytecode_runtime_head, struct list_head *enabler_bytecode_runtime_head); void lttng_free_event_filter_runtime(struct lttng_event *event); +void lttng_free_event_notifier_filter_runtime(struct lttng_event_notifier *event_notifier); int lttng_probes_init(void); diff --git a/src/lttng-bytecode.c b/src/lttng-bytecode.c index 5702929b..86ffe949 100644 --- a/src/lttng-bytecode.c +++ b/src/lttng-bytecode.c @@ -603,3 +603,14 @@ void lttng_free_event_filter_runtime(struct lttng_event *event) kfree(runtime); } } + +void lttng_free_event_notifier_filter_runtime(struct lttng_event_notifier *event_notifier) +{ + struct bytecode_runtime *runtime, *tmp; + + list_for_each_entry_safe(runtime, tmp, + &event_notifier->filter_bytecode_runtime_head, p.node) { + kfree(runtime->data); + kfree(runtime); + } +} diff --git a/src/lttng-events.c b/src/lttng-events.c index 3569be68..2bec7284 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -1526,6 +1526,8 @@ void _lttng_event_destroy(struct lttng_event *event) static void _lttng_event_notifier_destroy(struct lttng_event_notifier *event_notifier) { + struct lttng_enabler_ref *enabler_ref, *tmp_enabler_ref; + switch (event_notifier->instrumentation) { case LTTNG_KERNEL_TRACEPOINT: lttng_event_desc_put(event_notifier->desc); @@ -1547,6 +1549,11 @@ void _lttng_event_notifier_destroy(struct lttng_event_notifier *event_notifier) WARN_ON_ONCE(1); } list_del(&event_notifier->list); + lttng_free_event_notifier_filter_runtime(event_notifier); + /* Free event enabler refs */ + list_for_each_entry_safe(enabler_ref, tmp_enabler_ref, + &event_notifier->enablers_ref_head, node) + kfree(enabler_ref); kmem_cache_free(event_notifier_cache, event_notifier); }