Browse Source

Fix some coverity issues in the unit tests

Nick Mathewson 9 years ago
parent
commit
13f26f41e4
4 changed files with 17 additions and 5 deletions
  1. 9 1
      src/test/test_channel.c
  2. 6 2
      src/test/test_dir.c
  3. 1 2
      src/test/test_microdesc.c
  4. 1 0
      src/test/test_relay.c

+ 9 - 1
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;
 }
 

+ 6 - 2
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

+ 1 - 2
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));

+ 1 - 0
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);