[or-cvs] [tor/master] Improved fix for test_memeq_hex leak.
Nick Mathewson
nickm at seul.org
Sun Sep 27 16:11:22 UTC 2009
Author: Nick Mathewson <nickm at torproject.org>
Date: Sun, 27 Sep 2009 12:07:33 -0400
Subject: Improved fix for test_memeq_hex leak.
Commit: 008dc890d8d393f3a7be8ffae131632e46c5bc53
The earlier fix would only handle the success case. In the failing
case, test_mem_op does a goto done, which would leave the leak leaking.
---
src/test/test.h | 10 ++++++----
src/test/test_crypto.c | 4 ++++
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/test/test.h b/src/test/test.h
index 18238b3..ed0eb31 100644
--- a/src/test/test.h
+++ b/src/test/test.h
@@ -51,14 +51,16 @@
#define test_memeq(expr1, expr2, len) test_mem_op((expr1), ==, (expr2), len)
#define test_memneq(expr1, expr2, len) test_mem_op((expr1), !=, (expr2), len)
+/* As test_mem_op, but decodes 'hex' before comparing. There must be a
+ * local char* variable called mem_op_hex_tmp for this to work. */
#define test_mem_op_hex(expr1, op, hex) \
STMT_BEGIN \
size_t length = strlen(hex); \
- char *value2 = tor_malloc(length/2); \
+ tor_free(mem_op_hex_tmp); \
+ mem_op_hex_tmp = tor_malloc(length/2); \
tor_assert((length&1)==0); \
- base16_decode(value2, length/2, hex, length); \
- test_mem_op(expr1, op, value2, length/2); \
- tor_free(value2); \
+ base16_decode(mem_op_hex_tmp, length/2, hex, length); \
+ test_mem_op(expr1, op, mem_op_hex_tmp, length/2); \
STMT_END
#define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, ==, hex)
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
index d937d43..d235520 100644
--- a/src/test/test_crypto.c
+++ b/src/test/test_crypto.c
@@ -96,6 +96,7 @@ test_crypto_aes(void)
char *data1 = NULL, *data2 = NULL, *data3 = NULL;
crypto_cipher_env_t *env1 = NULL, *env2 = NULL;
int i, j;
+ char *mem_op_hex_tmp=NULL;
data1 = tor_malloc(1024);
data2 = tor_malloc(1024);
@@ -210,6 +211,7 @@ test_crypto_aes(void)
test_assert(tor_mem_is_zero(data2, 64));
done:
+ tor_free(mem_op_hex_tmp);
if (env1)
crypto_free_cipher_env(env1);
if (env2)
@@ -229,6 +231,7 @@ test_crypto_sha(void)
char digest[32];
char data[50];
char d_out1[DIGEST_LEN], d_out2[DIGEST256_LEN];
+ char *mem_op_hex_tmp=NULL;
/* Test SHA-1 with a test vector from the specification. */
i = crypto_digest(data, "abc", 3);
@@ -312,6 +315,7 @@ test_crypto_sha(void)
crypto_free_digest_env(d1);
if (d2)
crypto_free_digest_env(d2);
+ tor_free(mem_op_hex_tmp);
}
/** Run unit tests for our public key crypto functions */
--
1.5.6.5
More information about the tor-commits
mailing list