From 52263b0dda85632ea1deb0f05a83a39d4876f3ab Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 11 Feb 2013 15:20:20 -0500 Subject: [PATCH] Fix even more dead code and resource leaks in the unit tests Found by coverity --- src/test/bench.c | 8 ++++++-- src/test/test_replay.c | 6 ------ src/test/test_util.c | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/test/bench.c b/src/test/bench.c index 18a5154e11..5a8d21d173 100644 --- a/src/test/bench.c +++ b/src/test/bench.c @@ -124,8 +124,10 @@ bench_onion_TAP(void) key = crypto_pk_new(); key2 = crypto_pk_new(); - crypto_pk_generate_key_with_bits(key, 1024); - crypto_pk_generate_key_with_bits(key2, 1024); + if (crypto_pk_generate_key_with_bits(key, 1024) < 0) + goto done; + if (crypto_pk_generate_key_with_bits(key2, 1024) < 0) + goto done; reset_perftime(); start = perftime(); @@ -171,7 +173,9 @@ bench_onion_TAP(void) printf("Client-side, part 2: %f usec.\n", NANOCOUNT(start, end, iters)/1e3); + done: crypto_pk_free(key); + crypto_pk_free(key2); } #ifdef CURVE25519_ENABLED diff --git a/src/test/test_replay.c b/src/test/test_replay.c index be48df177e..de841ad594 100644 --- a/src/test/test_replay.c +++ b/src/test/test_replay.c @@ -24,7 +24,6 @@ test_replaycache_alloc(void) r = replaycache_new(600, 300); test_assert(r != NULL); - if (!r) goto done; done: if (r) replaycache_free(r); @@ -40,7 +39,6 @@ test_replaycache_miss(void) r = replaycache_new(600, 300); test_assert(r != NULL); - if (!r) goto done; result = replaycache_add_and_test_internal(1200, r, test_buffer, @@ -61,7 +59,6 @@ test_replaycache_hit(void) r = replaycache_new(600, 300); test_assert(r != NULL); - if (!r) goto done; result = replaycache_add_and_test_internal(1200, r, test_buffer, @@ -87,7 +84,6 @@ test_replaycache_age(void) r = replaycache_new(600, 300); test_assert(r != NULL); - if (!r) goto done; result = replaycache_add_and_test_internal(1200, r, test_buffer, @@ -119,7 +115,6 @@ test_replaycache_elapsed(void) r = replaycache_new(600, 300); test_assert(r != NULL); - if (!r) goto done; result = replaycache_add_and_test_internal(1200, r, test_buffer, @@ -146,7 +141,6 @@ test_replaycache_noexpire(void) r = replaycache_new(0, 0); test_assert(r != NULL); - if (!r) goto done; result = replaycache_add_and_test_internal(1200, r, test_buffer, diff --git a/src/test/test_util.c b/src/test/test_util.c index b7a69b205e..b17e414255 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -53,7 +53,6 @@ test_util_read_until_eof_impl(const char *fname, size_t file_len, fd = open(fifo_name, O_RDONLY|O_BINARY); tt_int_op(fd, >=, 0); str = read_file_to_str_until_eof(fd, read_limit, &sz); - close(fd); tt_assert(str != NULL); if (read_limit < file_len) @@ -69,6 +68,8 @@ test_util_read_until_eof_impl(const char *fname, size_t file_len, tor_free(fifo_name); tor_free(test_str); tor_free(str); + if (fd >= 0) + close(fd); } static void