[tor-commits] [tor/master] Fix some memory leaks in the unit tests

nickm at torproject.org nickm at torproject.org
Tue Dec 15 19:00:13 UTC 2015


commit a56fb58d6e1e93b95e2a060b61f3d00eab95a298
Author: Nick Mathewson <nickm at torproject.org>
Date:   Tue Dec 15 14:00:08 2015 -0500

    Fix some memory leaks in the unit tests
---
 src/test/test_connection.c |   21 +++++++++++++--------
 src/test/test_dns.c        |    2 ++
 src/test/test_tortls.c     |    4 ++++
 src/test/testing_common.c  |    1 +
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/test/test_connection.c b/src/test/test_connection.c
index 7e466a9..f6e08fd 100644
--- a/src/test/test_connection.c
+++ b/src/test/test_connection.c
@@ -501,21 +501,26 @@ test_conn_get_rend(void *arg)
   ;
 }
 
-#define sl_is_conn_assert(sl, conn) \
-  do { \
-    tt_assert(smartlist_len((sl)) == 1); \
-    tt_assert(smartlist_get((sl), 0) == (conn)); \
+#define sl_is_conn_assert(sl_input, conn) \
+  do {                                               \
+    the_sl = (sl_input);                             \
+    tt_assert(smartlist_len((the_sl)) == 1);         \
+    tt_assert(smartlist_get((the_sl), 0) == (conn)); \
+    smartlist_free(the_sl); the_sl = NULL;           \
   } while (0)
 
-#define sl_no_conn_assert(sl) \
-  do { \
-    tt_assert(smartlist_len((sl)) == 0); \
+#define sl_no_conn_assert(sl_input)          \
+  do {                                       \
+    the_sl = (sl_input);                     \
+    tt_assert(smartlist_len((the_sl)) == 0); \
+    smartlist_free(the_sl); the_sl = NULL;   \
   } while (0)
 
 static void
 test_conn_get_rsrc(void *arg)
 {
   dir_connection_t *conn = DOWNCAST(dir_connection_t, arg);
+  smartlist_t *the_sl = NULL;
   tt_assert(conn);
   assert_connection_ok(&conn->base_, time(NULL));
 
@@ -630,7 +635,7 @@ test_conn_get_rsrc(void *arg)
             == 0);
 
  done:
-  ;
+  smartlist_free(the_sl);
 }
 
 static void
diff --git a/src/test/test_dns.c b/src/test/test_dns.c
index b40a482..b781d6d 100644
--- a/src/test/test_dns.c
+++ b/src/test/test_dns.c
@@ -579,6 +579,7 @@ NS(test_main)(void *arg)
   tor_free(TO_CONN(exitconn)->address);
   tor_free(cache_entry->pending_connections);
   tor_free(cache_entry);
+  tor_free(exitconn);
   return;
 }
 
@@ -739,6 +740,7 @@ NS(test_main)(void *arg)
   tor_free(TO_CONN(exitconn)->address);
   tor_free(cache_entry->pending_connections);
   tor_free(cache_entry);
+  tor_free(exitconn);
   return;
 }
 
diff --git a/src/test/test_tortls.c b/src/test/test_tortls.c
index b4a3435..8602d9e 100644
--- a/src/test/test_tortls.c
+++ b/src/test/test_tortls.c
@@ -145,6 +145,7 @@ test_tortls_tor_tls_new(void *data)
   tt_want(tls);
   tor_tls_free(tls); tls = NULL;
 
+  SSL_CTX_free(client_tls_context->ctx);
   client_tls_context->ctx = NULL;
   tls = tor_tls_new(-1, 0);
   tt_assert(!tls);
@@ -1140,6 +1141,7 @@ test_tortls_check_lifetime(void *ignored)
   tor_free(tls->ssl->session);
   tor_free(tls->ssl);
   tor_free(tls);
+  X509_free(validCert);
 }
 #endif
 
@@ -1465,6 +1467,7 @@ test_tortls_try_to_extract_certs_from_tls(void *ignored)
   tt_assert(id_cert);
 
  done:
+  sk_X509_free(sess->cert_chain);
   tor_free(sess);
   tor_free(tls->ssl->session);
   tor_free(tls->ssl);
@@ -2166,6 +2169,7 @@ test_tortls_write(void *ignored)
 
  done:
   teardown_capture_of_logs(previous_log);
+  BIO_free(tls->ssl->rbio);
   tor_free(tls->ssl);
   tor_free(tls);
   tor_free(method);
diff --git a/src/test/testing_common.c b/src/test/testing_common.c
index 2ea158f..e20e9e6 100644
--- a/src/test/testing_common.c
+++ b/src/test/testing_common.c
@@ -297,6 +297,7 @@ main(int c, const char **v)
   tor_free_all(0);
   dmalloc_log_unfreed();
 #endif
+  crypto_global_cleanup();
 
   if (have_failed)
     return 1;



More information about the tor-commits mailing list