Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame^] | 1 | From b3fdf78b15beb940918da1e41eb68e24ba31bb87 Mon Sep 17 00:00:00 2001 |
| 2 | From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 3 | Date: Wed, 3 Mar 2021 10:10:16 -0500 |
| 4 | Subject: [PATCH 1/4] Fix: memory leaks on event destroy |
| 5 | |
| 6 | Both filter runtime and event enabler ref objects are owned by the |
| 7 | event, but are not freed upon destruction of the event object, thus |
| 8 | leaking memory. |
| 9 | |
| 10 | Upstream-status: backport |
| 11 | |
| 12 | Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 13 | Change-Id: Ice9b1c18b47584838aea2b965494d3c8391f4c84 |
| 14 | --- |
| 15 | lttng-events.c | 7 +++++++ |
| 16 | lttng-events.h | 1 + |
| 17 | 2 files changed, 8 insertions(+) |
| 18 | |
| 19 | diff --git a/lttng-events.c b/lttng-events.c |
| 20 | index f3398adc..984bd341 100644 |
| 21 | --- a/lttng-events.c |
| 22 | +++ b/lttng-events.c |
| 23 | @@ -919,6 +919,8 @@ int _lttng_event_unregister(struct lttng_event *event) |
| 24 | static |
| 25 | void _lttng_event_destroy(struct lttng_event *event) |
| 26 | { |
| 27 | + struct lttng_enabler_ref *enabler_ref, *tmp_enabler_ref; |
| 28 | + |
| 29 | switch (event->instrumentation) { |
| 30 | case LTTNG_KERNEL_TRACEPOINT: |
| 31 | lttng_event_put(event->desc); |
| 32 | @@ -944,6 +946,11 @@ void _lttng_event_destroy(struct lttng_event *event) |
| 33 | } |
| 34 | list_del(&event->list); |
| 35 | lttng_destroy_context(event->ctx); |
| 36 | + lttng_free_event_filter_runtime(event); |
| 37 | + /* Free event enabler refs */ |
| 38 | + list_for_each_entry_safe(enabler_ref, tmp_enabler_ref, |
| 39 | + &event->enablers_ref_head, node) |
| 40 | + kfree(enabler_ref); |
| 41 | kmem_cache_free(event_cache, event); |
| 42 | } |
| 43 | |
| 44 | diff --git a/lttng-events.h b/lttng-events.h |
| 45 | index 1b9ab167..13b6abf5 100644 |
| 46 | --- a/lttng-events.h |
| 47 | +++ b/lttng-events.h |
| 48 | @@ -716,6 +716,7 @@ int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler, |
| 49 | struct lttng_kernel_filter_bytecode __user *bytecode); |
| 50 | void lttng_enabler_event_link_bytecode(struct lttng_event *event, |
| 51 | struct lttng_enabler *enabler); |
| 52 | +void lttng_free_event_filter_runtime(struct lttng_event *event); |
| 53 | |
| 54 | int lttng_probes_init(void); |
| 55 | |
| 56 | -- |
| 57 | 2.19.1 |
| 58 | |