From 282e04bd98988b7a74395257b01960e3432d87da Mon Sep 17 00:00:00 2001 From: tedu Date: Wed, 23 Apr 2014 20:22:37 +0000 Subject: [PATCH] close socket in failure cases too --- lib/libcrypto/bio/b_sock.c | 3 +++ lib/libssl/src/crypto/bio/b_sock.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/libcrypto/bio/b_sock.c b/lib/libcrypto/bio/b_sock.c index a7791b39e2e..e5f42398df6 100644 --- a/lib/libcrypto/bio/b_sock.c +++ b/lib/libcrypto/bio/b_sock.c @@ -535,6 +535,7 @@ BIO_accept(int sock, char **addr) if (p) { *p = '\0'; if (!(tmp = realloc(p, nl))) { + close(ret); ret = -1; free(p); *addr = NULL; @@ -546,6 +547,7 @@ BIO_accept(int sock, char **addr) p = malloc(nl); } if (p == NULL) { + close(ret); ret = -1; BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); goto end; @@ -561,6 +563,7 @@ BIO_accept(int sock, char **addr) port = ntohs(sa.from.sa_in.sin_port); if (*addr == NULL) { if ((p = malloc(24)) == NULL) { + close(ret); ret = -1; BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); goto end; diff --git a/lib/libssl/src/crypto/bio/b_sock.c b/lib/libssl/src/crypto/bio/b_sock.c index a7791b39e2e..e5f42398df6 100644 --- a/lib/libssl/src/crypto/bio/b_sock.c +++ b/lib/libssl/src/crypto/bio/b_sock.c @@ -535,6 +535,7 @@ BIO_accept(int sock, char **addr) if (p) { *p = '\0'; if (!(tmp = realloc(p, nl))) { + close(ret); ret = -1; free(p); *addr = NULL; @@ -546,6 +547,7 @@ BIO_accept(int sock, char **addr) p = malloc(nl); } if (p == NULL) { + close(ret); ret = -1; BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); goto end; @@ -561,6 +563,7 @@ BIO_accept(int sock, char **addr) port = ntohs(sa.from.sa_in.sin_port); if (*addr == NULL) { if ((p = malloc(24)) == NULL) { + close(ret); ret = -1; BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); goto end; -- 2.20.1