diff mbox series

trace-cmd: Close socket descriptor on failed connection

Message ID 20220815171947.57e919df@gandalf.local.home (mailing list archive)
State Superseded
Headers show
Series trace-cmd: Close socket descriptor on failed connection | expand

Commit Message

Steven Rostedt Aug. 15, 2022, 9:19 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

In trace_vsock_open(), if the connection fails, the sd file descriptor
still needs to be closed.

Fixes: 76aaeb474 ("trace-cmd: Add VM kernel tracing over vsockets transport")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-vsock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-vsock.c b/tracecmd/trace-vsock.c
index 3bad9efad39a..baa310f7586b 100644
--- a/tracecmd/trace-vsock.c
+++ b/tracecmd/trace-vsock.c
@@ -19,8 +19,10 @@  int __hidden trace_vsock_open(unsigned int cid, unsigned int port)
 	if (sd < 0)
 		return -errno;
 
-	if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)))
+	if (connect(sd, (struct sockaddr *)&addr, sizeof(addr))) {
+		close(sd);
 		return -errno;
+	}
 
 	return sd;
 }