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

[tor-commits] [tor] 02/04: test_crypto: avoid memory leak in some hashx test failures



This is an automated email from the git hooks/post-receive script.

dgoulet pushed a commit to branch main
in repository tor.

commit a3ff3155c22e7cf093667c6c32166a8f9c77a79a
Author: Micah Elizabeth Scott <beth@xxxxxxxxxxxxxx>
AuthorDate: Thu May 11 11:17:43 2023 -0700

    test_crypto: avoid memory leak in some hashx test failures
    
    This should fix one of the warnings in issue #40792.
    
    I was sloppy with freeing memory in the failure cases for
    test_crypto_hashx. ASAN didn't notice but coverity did. Okay, I'll eat
    my vegetables and put hashx_ctx's deinit in an upper scope and use
    'goto done' correctly like a properly diligent C programmer.
    
    Signed-off-by: Micah Elizabeth Scott <beth@xxxxxxxxxxxxxx>
---
 src/test/test_crypto.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
index 82a9d5d642..926d4178c1 100644
--- a/src/test/test_crypto.c
+++ b/src/test/test_crypto.c
@@ -2990,6 +2990,7 @@ test_crypto_hashx(void *arg)
 
   const unsigned num_vectors = sizeof vectors / sizeof vectors[0];
   const unsigned num_variations = sizeof variations / sizeof variations[0];
+  hashx_ctx *ctx = NULL;
 
   for (unsigned vec_i = 0; vec_i < num_vectors; vec_i++) {
     const char *seed_literal = vectors[vec_i].seed_literal;
@@ -3008,7 +3009,9 @@ test_crypto_hashx(void *arg)
     for (unsigned vari_i = 0; vari_i < num_variations; vari_i++) {
       uint8_t out_actual[HASHX_SIZE] = { 0 };
 
-      hashx_ctx *ctx = hashx_alloc(variations[vari_i].type);
+      hashx_free(ctx);
+      ctx = hashx_alloc(variations[vari_i].type);
+
       tt_ptr_op(ctx, OP_NE, NULL);
       tt_ptr_op(ctx, OP_NE, HASHX_NOTSUPP);
       retval = hashx_make(ctx, seed_literal, seed_len);
@@ -3017,13 +3020,11 @@ test_crypto_hashx(void *arg)
       memset(out_actual, 0xa5, sizeof out_actual);
       hashx_exec(ctx, hash_input, out_actual);
       tt_mem_op(out_actual, OP_EQ, out_expected, sizeof out_actual);
-
-      hashx_free(ctx);
     }
   }
 
  done:
-  ;
+  hashx_free(ctx);
 }
 
 /* We want the likelihood that the random buffer exhibits any regular pattern

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits