[PATCH 07/15] libtracefs: prevent a memory leak in add_func_str()

"Jerome Marchand" <[email protected]>
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
Free func_list if strdup() fails.

Fixes a RESSOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <[email protected]>
---
 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.44.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.