From 402be29ae6fa1e29c963c71be2713687a4a71686 Mon Sep 17 00:00:00 2001 From: "Tzvetomir Stoyanov (VMware)" Date: Tue, 14 Sep 2021 16:12:15 +0300 Subject: [PATCH] trace-cmd library: Fixed a memory leak on input handler close When an input handler to a trace file is closed with tracecmd_close(), the list with buffers is not freed. This leads to a memory leak. Added logic to free that list. Link: https://lore.kernel.org/linux-trace-devel/20210914131232.3964615-5-tz.stoyanov@gmail.com Signed-off-by: Tzvetomir Stoyanov (VMware) Signed-off-by: Steven Rostedt (VMware) --- lib/trace-cmd/trace-input.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 9253bc37..ffe87e8a 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3484,6 +3484,7 @@ void tracecmd_ref(struct tracecmd_input *handle) void tracecmd_close(struct tracecmd_input *handle) { int cpu; + int i; if (!handle) return; @@ -3521,6 +3522,10 @@ void tracecmd_close(struct tracecmd_input *handle) free(handle->version); close(handle->fd); + for (i = 0; i < handle->nr_buffers; i++) + free(handle->buffers[i].name); + free(handle->buffers); + tracecmd_free_hooks(handle->hooks); handle->hooks = NULL; -- 2.33.0