From 7fcd8d27ff95670ffb0478486d408162f5299e89 Mon Sep 17 00:00:00 2001 From: Jerome Marchand Date: Thu, 6 Jun 2024 17:38:21 +0200 Subject: [PATCH 07/15] libtracefs: Prevent a memory leak in add_func_str() Free func_list if strdup() fails. Fixes a RESSOURCE_LEAK error (CWE-772) Link: https://lore.kernel.org/linux-trace-devel/20240606153830.2666120-8-jmarchan@redhat.com Fixes: c1606fb72264a ("libtracefs: Implement tracefs_filter_functions()") Signed-off-by: Jerome Marchand Signed-off-by: Steven Rostedt (Google) --- src/tracefs-tools.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c index 8e7b46d..74cfe91 100644 --- a/src/tracefs-tools.c +++ b/src/tracefs-tools.c @@ -559,8 +559,10 @@ static int add_func_str(struct func_list ***next_func_ptr, const char *func) if (!func_list) return -1; func_list->func = strdup(func); - if (!func_list->func) + if (!func_list->func) { + free(func_list); return -1; + } *next_func = func_list; return 0; } -- 2.45.2