1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

Avoid leaking a socket when SSL_accept fails.

This commit is contained in:
David Galeano 2013-01-10 10:45:24 +08:00 committed by Andy Green
parent 7c8d98924b
commit ed3c840ed6

View file

@ -1574,8 +1574,14 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
/* accepting connection to main listener */
new_wsi = libwebsocket_create_new_server_wsi(context);
if (new_wsi == NULL)
if (new_wsi == NULL) {
#ifdef WIN32
closesocket(accept_fd);
#else
close(accept_fd);
#endif
break;
}
new_wsi->sock = accept_fd;
@ -1592,6 +1598,11 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
new_wsi->ssl, 0), NULL));
libwebsockets_decode_ssl_error();
free(new_wsi);
#ifdef WIN32
closesocket(accept_fd);
#else
close(accept_fd);
#endif
break;
}
@ -1611,6 +1622,11 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
SSL_free(
new_wsi->ssl);
free(new_wsi);
#ifdef WIN32
closesocket(accept_fd);
#else
close(accept_fd);
#endif
break;
}
@ -2636,7 +2652,7 @@ libwebsocket_create_context(int port, const char *interf,
n = 0;
if (strlen(hostname) < sizeof(sa.sa_data) - 1) {
if (strlen(hostname) < sizeof(sa.sa_data) - 1) {
strcpy(sa.sa_data, hostname);
// fprintf(stderr, "my host name is %s\n", sa.sa_data);
n = getnameinfo(&sa, sizeof(sa), hostname,