diff mbox series

[30/38] trace-cmd listen: prevent memory leak in communicate_with_client()

Message ID 20240605134054.2626953-31-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit e0fe30349e43e1a9c0de385c4ecdd103dbc22c20
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
Free option in the error path.

Fixes a RESOURCE_LEAK error (CWE-772)

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

Patch

diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c
index 09f442c7..da46d09e 100644
--- a/tracecmd/trace-listen.c
+++ b/tracecmd/trace-listen.c
@@ -456,8 +456,10 @@  static int communicate_with_client(struct tracecmd_msg_handle *msg_handle)
 				t = size;
 				s = 0;
 				s = read(fd, option+s, t);
-				if (s <= 0)
+				if (s <= 0) {
+					free(option);
 					goto out;
+				}
 				t -= s;
 				s = size - t;
 			} while (t);