From c9abf5ebbb0a6e75bcf2cc3b4da90fb2cac10051 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Wed, 7 Jan 2026 13:25:25 +0100 Subject: [PATCH] connect: Avoid calling close with negative argument The `first` is intialized to -1 and if we reach this without setting this, we needlessly call close(-1). It should be no-op, but better be safe. Thanks coverity! CID 1644001 Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- src/connect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connect.c b/src/connect.c index b699ee54..0758e468 100644 --- a/src/connect.c +++ b/src/connect.c @@ -335,8 +335,8 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host, * connection, otherwise return the first address without error or error */ if (s == -1) { s = first; - } else if (s != first) { - /* Clean up the saved socket */ + } else if (s != first && first != -1) { + /* Clean up the saved socket if any */ ssh_connect_socket_close(first); }