Quellcode durchsuchen

Expose desc_intro_point_free to the tests, and use it.

Also fix another couple of leaks.
Nick Mathewson vor 7 Jahren
Ursprung
Commit
a4291eef5a
3 geänderte Dateien mit 11 neuen und 5 gelöschten Zeilen
  1. 1 1
      src/or/hs_descriptor.c
  2. 1 1
      src/or/hs_descriptor.h
  3. 9 3
      src/test/test_hs_descriptor.c

+ 1 - 1
src/or/hs_descriptor.c

@@ -77,7 +77,7 @@ static token_rule_t hs_desc_intro_point_v3_token_table[] = {
 };
 
 /* Free a descriptor intro point object. */
-static void
+STATIC void
 desc_intro_point_free(hs_desc_intro_point_t *ip)
 {
   if (!ip) {

+ 1 - 1
src/or/hs_descriptor.h

@@ -232,7 +232,7 @@ STATIC int cert_is_valid(tor_cert_t *cert, uint8_t type,
 STATIC int desc_sig_is_valid(const char *b64_sig,
                              const ed25519_keypair_t *signing_kp,
                              const char *encoded_desc, size_t encoded_len);
-
+STATIC void desc_intro_point_free(hs_desc_intro_point_t *ip);
 #endif /* HS_DESCRIPTOR_PRIVATE */
 
 #endif /* TOR_HS_DESCRIPTOR_H */

+ 9 - 3
src/test/test_hs_descriptor.c

@@ -593,7 +593,7 @@ test_decode_intro_point(void *arg)
   int ret;
   char *encoded_ip = NULL;
   size_t len_out;
-  hs_desc_intro_point_t *ip;
+  hs_desc_intro_point_t *ip = NULL;
   hs_descriptor_t *desc = NULL;
 
   (void) arg;
@@ -673,6 +673,8 @@ test_decode_intro_point(void *arg)
     const char *junk = "this is not a descriptor";
     ip = decode_introduction_point(desc, junk);
     tt_assert(!ip);
+    desc_intro_point_free(ip);
+    ip = NULL;
   }
 
   /* Invalid link specifiers. */
@@ -689,6 +691,8 @@ test_decode_intro_point(void *arg)
     tt_assert(!ip);
     tor_free(encoded_ip);
     smartlist_free(lines);
+    desc_intro_point_free(ip);
+    ip = NULL;
   }
 
   /* Invalid auth key type. */
@@ -803,6 +807,7 @@ test_decode_intro_point(void *arg)
 
  done:
   hs_descriptor_free(desc);
+  desc_intro_point_free(ip);
 }
 
 const char encrypted_desc_portion[] = "create2-formats 2\n"
@@ -1027,6 +1032,7 @@ test_validate_cert(void *arg)
   int ret;
   time_t now = time(NULL);
   ed25519_keypair_t kp;
+  tor_cert_t *cert = NULL;
 
   (void) arg;
 
@@ -1034,7 +1040,7 @@ test_validate_cert(void *arg)
   tt_int_op(ret, ==, 0);
 
   /* Cert of type CERT_TYPE_AUTH_HS_IP_KEY. */
-  tor_cert_t *cert = tor_cert_create(&kp, CERT_TYPE_AUTH_HS_IP_KEY,
+  cert = tor_cert_create(&kp, CERT_TYPE_AUTH_HS_IP_KEY,
                                      &kp.pubkey, now, 3600,
                                      CERT_FLAG_INCLUDE_SIGNING_KEY);
   tt_assert(cert);
@@ -1062,7 +1068,7 @@ test_validate_cert(void *arg)
   tt_int_op(ret, OP_EQ, 0);
 
  done:
-  ;
+  tor_cert_free(cert);
 }
 
 static void