mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Fix some coverity issues in the unit tests
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user