1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00

openssh_fixture: fix to close socket on connect failure

Closes #1855
This commit is contained in:
Viktor Szakats
2026-04-11 03:46:51 +02:00
parent 2e69ba25a4
commit 5ddc599720

View File

@@ -337,6 +337,18 @@ static int port_from_container(char *container_id, char **port_out)
}
}
static void close_socket_to_container(libssh2_socket_t sock)
{
if(sock != LIBSSH2_INVALID_SOCKET) {
shutdown(sock, 2 /* SHUT_RDWR */);
#ifdef _WIN32
closesocket(sock);
#else
close(sock);
#endif
}
}
static libssh2_socket_t open_socket_to_container(char *container_id)
{
char *ip_address = NULL;
@@ -416,6 +428,7 @@ static libssh2_socket_t open_socket_to_container(char *container_id)
}
}
if(ret == LIBSSH2_INVALID_SOCKET) {
close_socket_to_container(sock);
fprintf(stderr, "Failed to connect to %s:%s\n",
ip_address, port_string);
goto cleanup;
@@ -428,18 +441,6 @@ cleanup:
return ret;
}
static void close_socket_to_container(libssh2_socket_t sock)
{
if(sock != LIBSSH2_INVALID_SOCKET) {
shutdown(sock, 2 /* SHUT_RDWR */);
#ifdef _WIN32
closesocket(sock);
#else
close(sock);
#endif
}
}
static char *running_container_id = NULL;
int start_openssh_fixture(void)