[tor-commits] [tor/master] Fix some memory leaks in ed25519 code and tests

nickm at torproject.org nickm at torproject.org
Mon Jun 1 14:26:13 UTC 2015


commit d31877c6bf68c942b6c66bc7a59781d75a3dc3b5
Author: Nick Mathewson <nickm at torproject.org>
Date:   Mon Jun 1 10:26:11 2015 -0400

    Fix some memory leaks in ed25519 code and tests
---
 src/or/dircollate.c       |    1 +
 src/test/test_dir.c       |   12 +++++++-----
 src/test/test_microdesc.c |    1 +
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/or/dircollate.c b/src/or/dircollate.c
index 34259ec..331e058 100644
--- a/src/or/dircollate.c
+++ b/src/or/dircollate.c
@@ -125,6 +125,7 @@ dircollator_free(dircollator_t *dc)
     digestmap_free(dc->by_collated_rsa_sha1, NULL);
 
   digestmap_free(dc->by_rsa_sha1, tor_free_);
+  smartlist_free(dc->all_rsa_sha1_lst);
 
   ddmap_entry_t **e, **next, *this;
   for (e = HT_START(double_digest_map, &dc->by_both_ids);
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 3e9e955..32ac8d4 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -91,7 +91,6 @@ test_dir_formats(void *arg)
   addr_policy_t *ex1, *ex2;
   routerlist_t *dir1 = NULL, *dir2 = NULL;
   uint8_t *rsa_cc = NULL;
-  tor_cert_t *ntor_cc = NULL;
   or_options_t *options = get_options_mutable();
   const addr_policy_t *p;
   time_t now = time(NULL);
@@ -155,7 +154,6 @@ test_dir_formats(void *arg)
   r2->or_port = 9005;
   r2->dir_port = 0;
   r2->onion_pkey = crypto_pk_dup_key(pk2);
-  r2->onion_curve25519_pkey = tor_malloc_zero(sizeof(curve25519_public_key_t));
   curve25519_keypair_t r2_onion_keypair;
   curve25519_keypair_generate(&r2_onion_keypair, 0);
   r2->onion_curve25519_pkey = tor_memdup(&r2_onion_keypair.pubkey,
@@ -257,15 +255,19 @@ test_dir_formats(void *arg)
   strlcat(buf2, cert_buf, sizeof(buf2));
   strlcat(buf2, "-----END CROSSCERT-----\n", sizeof(buf2));
   int ntor_cc_sign;
-  ntor_cc = make_ntor_onion_key_crosscert(&r2_onion_keypair,
+  {
+    tor_cert_t *ntor_cc = NULL;
+    ntor_cc = make_ntor_onion_key_crosscert(&r2_onion_keypair,
                                           &kp1.pubkey,
                                           r2->cache_info.published_on,
                                           MIN_ONION_KEY_LIFETIME,
                                           &ntor_cc_sign);
-  tt_assert(ntor_cc);
-  base64_encode(cert_buf, sizeof(cert_buf),
+    tt_assert(ntor_cc);
+    base64_encode(cert_buf, sizeof(cert_buf),
                 (char*)ntor_cc->encoded, ntor_cc->encoded_len,
                 BASE64_ENCODE_MULTILINE);
+    tor_cert_free(ntor_cc);
+  }
   tor_snprintf(buf2+strlen(buf2), sizeof(buf2)-strlen(buf2),
                "ntor-onion-key-crosscert %d\n"
                "-----BEGIN ED25519 CERT-----\n"
diff --git a/src/test/test_microdesc.c b/src/test/test_microdesc.c
index 3c22e18..5dc5b2b 100644
--- a/src/test/test_microdesc.c
+++ b/src/test/test_microdesc.c
@@ -470,6 +470,7 @@ test_md_generate(void *arg)
   md = dirvote_create_microdescriptor(ri, 21);
   tt_str_op(md->body, ==, test_md_18);
 
+  routerinfo_free(ri);
   ri = router_parse_entry_from_string(test_ri2, NULL, 0, 0, NULL, NULL);
 
   microdesc_free(md);



More information about the tor-commits mailing list