diff mbox series

[37/38] trace-cmd record: close socket fd before retrying to connect

Message ID 20240605134054.2626953-38-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit 5141fd925037b3ef1f2f8d14ffc9ddce91b1cfd8
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
In create_record(), if the client whose conection it just accepted
doesn't match, it tries to call get another connection without
releasing the socket file descriptor.

Close the file descriptor before retrying to connect.

Fixes a RESOURCE_LEAK error (CWE-772)

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

Patch

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index c3118546..0191ef2a 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3651,6 +3651,7 @@  static int create_recorder(struct buffer_instance *instance, int cpu,
 				    !trace_net_cmp_connection_fd(fd, instance->host)) {
 					dprint("Client does not match '%s' for cpu:%d\n",
 					       instance->host, cpu);
+					close(fd);
 					goto again;
 				}
 			}