commit aa0eb2022342798fc78b2bde89d393f37c59fe78 Author: Nick Mathewson nickm@torproject.org Date: Sat Apr 26 14:48:30 2014 -0400
Fix leaks in tests related to setting options->DataDirectory
We pre-populate that value in main(), and we weren't freeing it before overriding it. --- src/test/test_config.c | 13 ++++++++++--- src/test/test_extorport.c | 1 + src/test/test_microdesc.c | 1 + src/test/test_routerkeys.c | 1 + 4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/test/test_config.c b/src/test/test_config.c index 82bc92d..d3e3252 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -196,9 +196,9 @@ static void test_config_check_or_create_data_subdir(void *arg) { or_options_t *options = get_options_mutable(); - char *datadir = options->DataDirectory = tor_strdup(get_fname("datadir-0")); + char *datadir; const char *subdir = "test_stats"; - char *subpath = get_datadir_fname(subdir); + char *subpath; struct stat st; int r; #if !defined (_WIN32) || defined (WINCE) @@ -206,6 +206,10 @@ test_config_check_or_create_data_subdir(void *arg) #endif (void)arg;
+ tor_free(options->DataDirectory); + datadir = options->DataDirectory = tor_strdup(get_fname("datadir-0")); + subpath = get_datadir_fname(subdir); + #if defined (_WIN32) && !defined (WINCE) tt_int_op(mkdir(options->DataDirectory), ==, 0); #else @@ -254,7 +258,7 @@ static void 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 *datadir; char *cp = NULL; const char* subdir = "test_stats"; const char* fname = "test_file"; @@ -276,6 +280,9 @@ test_config_write_to_data_subdir(void *arg) char* filepath = get_datadir_fname2(subdir, fname); (void)arg;
+ tor_free(options->DataDirectory); + datadir = options->DataDirectory = tor_strdup(get_fname("datadir-1")); + #if defined (_WIN32) && !defined (WINCE) tt_int_op(mkdir(options->DataDirectory), ==, 0); #else diff --git a/src/test/test_extorport.c b/src/test/test_extorport.c index f91ac74..d47792f 100644 --- a/src/test/test_extorport.c +++ b/src/test/test_extorport.c @@ -172,6 +172,7 @@ test_ext_or_init_auth(void *arg) (void)arg;
/* Check default filename location */ + tor_free(options->DataDirectory); options->DataDirectory = tor_strdup("foo"); cp = get_ext_or_auth_cookie_file_name(); tt_str_op(cp, ==, "foo"PATH_SEPARATOR"extended_orport_auth_cookie"); diff --git a/src/test/test_microdesc.c b/src/test/test_microdesc.c index 53a03a4..2982484 100644 --- a/src/test/test_microdesc.c +++ b/src/test/test_microdesc.c @@ -261,6 +261,7 @@ test_md_cache_broken(void *data)
options = get_options_mutable(); tt_assert(options); + tor_free(options->DataDirectory); options->DataDirectory = tor_strdup(get_fname("md_datadir_test2"));
#ifdef _WIN32 diff --git a/src/test/test_routerkeys.c b/src/test/test_routerkeys.c index 1c8174b..182e0f6 100644 --- a/src/test/test_routerkeys.c +++ b/src/test/test_routerkeys.c @@ -27,6 +27,7 @@ test_routerkeys_write_fingerprint(void *arg) tt_assert(key);
options->ORPort_set = 1; /* So that we can get the server ID key */ + tor_free(options->DataDirectory); options->DataDirectory = tor_strdup(ddir); options->Nickname = tor_strdup("haflinger"); set_server_identity_key(key);
tor-commits@lists.torproject.org