diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-09-27 12:07:33 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-09-27 12:07:33 -0400 |
commit | 008dc890d8d393f3a7be8ffae131632e46c5bc53 (patch) | |
tree | 59489aae0f59270ceaf22da464b127becc5d9c23 /src/test/test.h | |
parent | a24b9e60884f6aec1bfbe8da20a02d1fdc0cd181 (diff) | |
download | tor-008dc890d8d393f3a7be8ffae131632e46c5bc53.tar.gz tor-008dc890d8d393f3a7be8ffae131632e46c5bc53.zip |
Improved fix for test_memeq_hex leak.
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.
Diffstat (limited to 'src/test/test.h')
-rw-r--r-- | src/test/test.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/test/test.h b/src/test/test.h index 18238b3301..ed0eb316ad 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) |