From c50537fd9462af45f0a53aa4f0d5ca03a08fc41e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 4 Sep 2018 19:23:55 -0400 Subject: Fix a pair of remaining leaks in tortls_nss.c Fun fact: PR_Close leaks memory if its socket is not valid. --- src/lib/tls/tortls_nss.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/lib/tls/tortls_nss.c') diff --git a/src/lib/tls/tortls_nss.c b/src/lib/tls/tortls_nss.c index 548a817e63..8e6c0d2d77 100644 --- a/src/lib/tls/tortls_nss.c +++ b/src/lib/tls/tortls_nss.c @@ -361,7 +361,13 @@ tor_tls_new(tor_socket_t sock, int is_server) (void)sock; tor_tls_context_t *ctx = tor_tls_context_get(is_server); - PRFileDesc *tcp = PR_ImportTCPSocket(sock); + PRFileDesc *tcp = NULL; + if (SOCKET_OK(sock)) { + tcp = PR_ImportTCPSocket(sock); + } else { + tcp = PR_NewTCPSocket(); + } + if (!tcp) return NULL; -- cgit v1.2.3-54-g00ecf