From 684c9afcc6f3c4e6976c25bafd70b3507840f861 Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Sat, 9 Sep 2017 00:44:24 +0300 Subject: [PATCH] sslh-select: actually close socket on error in accept_new_connection Previously, it was leaked (and the client was left waiting for a timeout). --- sslh-select.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sslh-select.c b/sslh-select.c index 765284e..146e1ca 100644 --- a/sslh-select.c +++ b/sslh-select.c @@ -93,11 +93,16 @@ int accept_new_connection(int listen_socket, struct connection *cnx[], int* cnx_ in_socket = accept(listen_socket, 0, 0); CHECK_RES_RETURN(in_socket, "accept"); - if (!fd_is_in_range(in_socket)) + if (!fd_is_in_range(in_socket)) { + close(in_socket); return -1; + } res = set_nonblock(in_socket); - if (res == -1) return -1; + if (res == -1) { + close(in_socket); + return -1; + } /* Find an empty slot */ for (free = 0; (free < *cnx_size) && ((*cnx)[free].q[0].fd != -1); free++) { @@ -109,6 +114,7 @@ int accept_new_connection(int listen_socket, struct connection *cnx[], int* cnx_ new = realloc(*cnx, (*cnx_size + cnx_num_alloc) * sizeof((*cnx)[0])); if (!new) { log_message(LOG_ERR, "unable to realloc -- dropping connection\n"); + close(in_socket); return -1; } *cnx = new;