[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Free leakable values in the unit tests.
commit c3720c05fa44b3790ab0dc37e2506ee482796e21
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Tue Feb 11 18:10:33 2014 -0500
Free leakable values in the unit tests.
Thanks, Coverity! (CID 1171414, 1171415, 1171416)
---
src/test/test.c | 6 ++++--
src/test/test_config.c | 11 +++++++++--
src/test/test_dir.c | 4 +++-
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/test/test.c b/src/test/test.c
index 522f2af..45f7c09 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -875,6 +875,7 @@ test_policies(void)
{
int i;
char *policy = NULL;
+ short_policy_t *parsed;
smartlist_t *chunks = smartlist_new();
smartlist_add(chunks, tor_strdup("accept "));
for (i=1; i<10000; ++i)
@@ -883,8 +884,9 @@ test_policies(void)
policy = smartlist_join_strings(chunks, "", 0, NULL);
SMARTLIST_FOREACH(chunks, char *, ch, tor_free(ch));
smartlist_free(chunks);
- tt_ptr_op(NULL, ==, parse_short_policy(policy));/* shouldn't be accepted */
- tor_free(policy); /* could leak. */
+ parsed = parse_short_policy(policy);/* shouldn't be accepted */
+ tor_free(policy);
+ tt_ptr_op(NULL, ==, parsed);
}
/* truncation ports */
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 3a1b6d7..a1dff64 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -247,6 +247,7 @@ test_config_write_to_data_subdir(void *arg)
{
or_options_t* options = get_options_mutable();
char *datadir = options->DataDirectory = tor_strdup(get_fname("datadir-1"));
+ char *cp = NULL;
const char* subdir = "test_stats";
const char* fname = "test_file";
const char* str =
@@ -280,17 +281,23 @@ test_config_write_to_data_subdir(void *arg)
// Content of file after write attempt should be
// equal to the original string.
test_assert(!write_to_data_subdir(subdir, fname, str, NULL));
- test_streq(read_file_to_str(filepath, 0, NULL), str);
+ cp = read_file_to_str(filepath, 0, NULL);
+ test_streq(cp, str);
+ tor_free(cp);
// A second write operation should overwrite the old content.
test_assert(!write_to_data_subdir(subdir, fname, str, NULL));
- test_streq(read_file_to_str(filepath, 0, NULL), str);
+ cp = read_file_to_str(filepath, 0, NULL);
+ test_streq(cp, str);
+ tor_free(cp);
+
done:
(void) unlink(filepath);
rmdir(options->DataDirectory);
tor_free(datadir);
tor_free(filepath);
+ tor_free(cp);
}
/* Test helper function: Make sure that a bridge line gets parsed
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 7c625ce..dcfe98d 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -1230,7 +1230,8 @@ test_a_networkstatus(
vote_routerstatus_t *vrs;
routerstatus_t *rs;
int idx, n_rs, n_vrs;
- char *v1_text=NULL, *v2_text=NULL, *v3_text=NULL, *consensus_text=NULL, *cp;
+ char *v1_text=NULL, *v2_text=NULL, *v3_text=NULL, *consensus_text=NULL,
+ *cp=NULL;
smartlist_t *votes = smartlist_new();
/* For generating the two other consensuses. */
@@ -1648,6 +1649,7 @@ test_a_networkstatus(
}
done:
+ tor_free(cp);
smartlist_free(votes);
tor_free(v1_text);
tor_free(v2_text);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits