diff mbox series

[4/7] trace-cmd lib: Prevent memory leak in tracecmd_msg_wait_for_cmd()

Message ID 20241205144439.127564-5-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit b948fbedf26163b1e8c8e9f61ef4d721257cc300
Headers show
Series trace-cmd: Fix misc issues uncoverd by static analysis | expand

Commit Message

Jerome Marchand Dec. 5, 2024, 2:44 p.m. UTC
When tracecmd_msg_wait_for_cmd() returns successfully, msg->buf isn't
freed. Call msg_free() to free it.

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

Patch

diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c
index f5c604f1..c7583587 100644
--- a/lib/trace-cmd/trace-msg.c
+++ b/lib/trace-cmd/trace-msg.c
@@ -1034,8 +1034,10 @@  static int tracecmd_msg_wait_for_cmd(struct tracecmd_msg_handle *msg_handle, enu
 		if (ret < 0)
 			goto error;
 
-		if (ntohl(msg.hdr.cmd) == cmd)
+		if (ntohl(msg.hdr.cmd) == cmd) {
+			msg_free(&msg);
 			return 0;
+		}
 
 		error_operation(&msg);
 		ret = handle_unexpected_msg(msg_handle, &msg);