diff mbox series

[12/38] trace-cmd hist: close tracecmd handle when trace_hist() exits early

Message ID 20240605134054.2626953-13-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit 9cd86e37b7a10d1b5333dddd26eae853c32da27a
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand June 5, 2024, 1:40 p.m. UTC
Call tracecmd_close() before returning if tracecmd_read_headers() fails.

Fixes a RESOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 tracecmd/trace-hist.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-hist.c b/tracecmd/trace-hist.c
index 62fe4f9b..47dcd6f8 100644
--- a/tracecmd/trace-hist.c
+++ b/tracecmd/trace-hist.c
@@ -1043,8 +1043,10 @@  void trace_hist(int argc, char **argv)
 		die("can't open %s\n", input_file);
 
 	ret = tracecmd_read_headers(handle, 0);
-	if (ret)
+	if (ret) {
+		tracecmd_close(handle);
 		return;
+	}
 
 	ret = tracecmd_init_data(handle);
 	if (ret < 0)