[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Fix a pair of remaining leaks in tortls_nss.c



commit c50537fd9462af45f0a53aa4f0d5ca03a08fc41e
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Sep 4 19:23:55 2018 -0400

    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 +++++++-
 src/test/test_router.c   | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/lib/tls/tortls_nss.c b/src/lib/tls/tortls_nss.c
index 548a817e6..8e6c0d2d7 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;
 
diff --git a/src/test/test_router.c b/src/test/test_router.c
index c6a2452c8..14e739d6f 100644
--- a/src/test/test_router.c
+++ b/src/test/test_router.c
@@ -52,6 +52,8 @@ NS(router_get_my_routerinfo)(void)
     mock_routerinfo->onion_pkey = crypto_pk_dup_key(tap_key);
     mock_routerinfo->bandwidthrate = 9001;
     mock_routerinfo->bandwidthburst = 9002;
+    crypto_pk_free(ident_key);
+    crypto_pk_free(tap_key);
   }
 
   return mock_routerinfo;



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits