Close the socket file descriptor in the error paths. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand <jmarchan@xxxxxxxxxx> --- tracecmd/trace-vsock.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tracecmd/trace-vsock.c b/tracecmd/trace-vsock.c index baa310f7..df1a9800 100644 --- a/tracecmd/trace-vsock.c +++ b/tracecmd/trace-vsock.c @@ -43,12 +43,16 @@ int __hidden trace_vsock_make(unsigned int port) setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)); if (bind(sd, (struct sockaddr *)&addr, sizeof(addr))) - return -errno; + goto error; if (listen(sd, SOMAXCONN)) - return -errno; + goto error; return sd; + +error: + close(sd); + return -errno; } int __hidden trace_vsock_make_any(void) -- 2.44.0