Fix: memory leaks on event notifier destroy
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 3 Mar 2021 15:22:38 +0000 (10:22 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 3 Mar 2021 18:15:46 +0000 (13:15 -0500)
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 <mathieu.desnoyers@efficios.com>
Change-Id: I511569f56a38f670549a93cb6179b77861245712

include/lttng/events.h
src/lttng-bytecode.c
src/lttng-events.c

index e6572680e6c6af76c28a55ae9b4df0cf6800be51..6aa880f82eb1b8737dad767b0c5e94a23a159888 100644 (file)
@@ -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);
 
index 5702929bd4a44fe9c95dd49ef2f324452c47e0ec..86ffe94985147aec879dc9e9151d95ade9af83b7 100644 (file)
@@ -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);
+       }
+}
index 3569be68d1151077182b60b996905538b9f10cea..2bec72847e36760f93fc5d04400b501b50149c34 100644 (file)
@@ -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);
 }
 
This page took 0.028406 seconds and 4 git commands to generate.