diff --git a/src/connect.c b/src/connect.c index 8d1855fb..be891003 100644 --- a/src/connect.c +++ b/src/connect.c @@ -281,8 +281,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); }