diff mbox series

[6/8] trace-cmd lib: Prevent memory leak in tracecmd_create_event_hook()

Message ID 20241029080117.625177-7-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit 1b901134a9e9eacc9c80646a12d27b761d89afd8
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand Oct. 29, 2024, 8:01 a.m. UTC
Free hook and hook->str in the error path.

Fixes a RESOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 lib/trace-cmd/trace-hooks.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-hooks.c b/lib/trace-cmd/trace-hooks.c
index a58b5356..aa12f6e9 100644
--- a/lib/trace-cmd/trace-hooks.c
+++ b/lib/trace-cmd/trace-hooks.c
@@ -151,6 +151,8 @@  struct hook_list *tracecmd_create_event_hook(const char *arg)
 
 invalid_tok:
 	tracecmd_warning("Invalid hook format '%s'", arg);
+	free(hook->str);
+	free(hook);
 	return NULL;
 }