Message ID | 20241029080117.625177-6-jmarchan@redhat.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 52946308c37e49d7dd0a28b067bf24f4079d5d21 |
Headers | show |
Series | trace-cmd: fix misc issues found by static analysis | expand |
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 3c42cdf0..7e84e897 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3904,6 +3904,7 @@ static struct tracecmd_msg_handle *setup_network(struct buffer_instance *instanc if (sfd < 0) { free(thost); + tracecmd_msg_handle_close(msg_handle); return NULL; } @@ -3934,6 +3935,7 @@ static struct tracecmd_msg_handle *setup_network(struct buffer_instance *instanc if (msg_handle->version == V1_PROTOCOL) { /* reconnect to the server for using the v1 protocol */ close(sfd); + msg_handle->fd = -1; free(host); host = NULL; goto again;
Because of the again label, msg_handle can be already allocated if we exit after we got a negative socket file descriptor. Free it there. Also unassign msg_handle->fd as to not double close sfd. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand <jmarchan@redhat.com> --- tracecmd/trace-record.c | 2 ++ 1 file changed, 2 insertions(+)