[tor-commits] [tor/master] Fix some coverity issues in the unit tests
nickm at torproject.org
nickm at torproject.org
Mon Dec 22 16:13:18 UTC 2014
commit 13f26f41e469ae2fa5d2249c532f7f515195a2a0
Author: Nick Mathewson <nickm at torproject.org>
Date: Mon Dec 22 11:13:01 2014 -0500
Fix some coverity issues in the unit tests
---
src/test/test_channel.c | 10 +++++++++-
src/test/test_dir.c | 8 ++++++--
src/test/test_microdesc.c | 3 +--
src/test/test_relay.c | 1 +
4 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/test/test_channel.c b/src/test/test_channel.c
index f882b99..b1f1bdb 100644
--- a/src/test/test_channel.c
+++ b/src/test/test_channel.c
@@ -1566,12 +1566,15 @@ test_channel_write(void *arg)
old_count = test_cells_written;
channel_write_cell(ch, cell);
+ cell = NULL;
tt_assert(test_cells_written == old_count + 1);
channel_write_var_cell(ch, var_cell);
+ var_cell = NULL;
tt_assert(test_cells_written == old_count + 2);
channel_write_packed_cell(ch, packed_cell);
+ packed_cell = NULL;
tt_assert(test_cells_written == old_count + 3);
/* Now we test queueing; tell it not to accept cells */
@@ -1632,15 +1635,18 @@ test_channel_write(void *arg)
cell = tor_malloc_zero(sizeof(cell_t));
make_fake_cell(cell);
channel_write_cell(ch, cell);
+ cell = NULL;
tt_assert(test_cells_written == old_count);
var_cell = tor_malloc_zero(sizeof(var_cell_t) + CELL_PAYLOAD_SIZE);
make_fake_var_cell(var_cell);
channel_write_var_cell(ch, var_cell);
+ var_cell = NULL;
tt_assert(test_cells_written == old_count);
packed_cell = packed_cell_new();
channel_write_packed_cell(ch, packed_cell);
+ packed_cell = NULL;
tt_assert(test_cells_written == old_count);
#ifdef ENABLE_MEMPOOLS
@@ -1649,7 +1655,9 @@ test_channel_write(void *arg)
done:
tor_free(ch);
-
+ tor_free(var_cell);
+ tor_free(cell);
+ packed_cell_free(packed_cell);
return;
}
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index e5328fe..2659fbc 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -605,6 +605,7 @@ test_dir_load_routers(void *arg)
smartlist_t *wanted = smartlist_new();
char buf[DIGEST_LEN];
char *mem_op_hex_tmp = NULL;
+ char *list = NULL;
#define ADD(str) \
do { \
@@ -630,7 +631,7 @@ test_dir_load_routers(void *arg)
/* Not ADDing BAD_PORTS */
ADD(EX_RI_BAD_TOKENS);
- char *list = smartlist_join_strings(chunks, "", 0, NULL);
+ list = smartlist_join_strings(chunks, "", 0, NULL);
tt_int_op(1, OP_EQ,
router_load_routers_from_string(list, NULL, SAVED_IN_JOURNAL,
wanted, 1, NULL));
@@ -670,6 +671,7 @@ test_dir_load_routers(void *arg)
smartlist_free(chunks);
SMARTLIST_FOREACH(wanted, char *, cp, tor_free(cp));
smartlist_free(wanted);
+ tor_free(list);
}
static int mock_get_by_ei_dd_calls = 0;
@@ -722,6 +724,7 @@ test_dir_load_extrainfo(void *arg)
smartlist_t *wanted = smartlist_new();
char buf[DIGEST_LEN];
char *mem_op_hex_tmp = NULL;
+ char *list = NULL;
#define ADD(str) \
do { \
@@ -746,7 +749,7 @@ test_dir_load_extrainfo(void *arg)
ADD(EX_EI_BAD_TOKENS);
ADD(EX_EI_BAD_SIG2);
- char *list = smartlist_join_strings(chunks, "", 0, NULL);
+ list = smartlist_join_strings(chunks, "", 0, NULL);
router_load_extrainfo_from_string(list, NULL, SAVED_IN_JOURNAL, wanted, 1);
/* The "maximal" router was added. */
@@ -788,6 +791,7 @@ test_dir_load_extrainfo(void *arg)
smartlist_free(chunks);
SMARTLIST_FOREACH(wanted, char *, cp, tor_free(cp));
smartlist_free(wanted);
+ tor_free(list);
}
static void
diff --git a/src/test/test_microdesc.c b/src/test/test_microdesc.c
index 4a7c29b..31ed93b 100644
--- a/src/test/test_microdesc.c
+++ b/src/test/test_microdesc.c
@@ -703,8 +703,7 @@ test_md_reject_cache(void *arg)
done:
UNMOCK(networkstatus_get_latest_consensus_by_flavor);
UNMOCK(router_get_mutable_consensus_status_by_descriptor_digest);
- if (options)
- tor_free(options->DataDirectory);
+ tor_free(options->DataDirectory);
microdesc_free_all();
smartlist_free(added);
SMARTLIST_FOREACH(wanted, char *, cp, tor_free(cp));
diff --git a/src/test/test_relay.c b/src/test/test_relay.c
index 6907597..38d1d96 100644
--- a/src/test/test_relay.c
+++ b/src/test/test_relay.c
@@ -114,6 +114,7 @@ test_relay_append_cell_to_circuit_queue(void *arg)
nchan = pchan = NULL;
done:
+ tor_free(cell);
tor_free(orcirc);
if (nchan && nchan->cmux) circuitmux_free(nchan->cmux);
tor_free(nchan);
More information about the tor-commits
mailing list