Ver código fonte

Fix a couple of resource leaks in test_config.c

Spotted by Coverity Scan. Not in any released Tor.
Nick Mathewson 12 anos atrás
pai
commit
9f8e672b50
1 arquivos alterados com 4 adições e 4 exclusões
  1. 4 4
      src/test/test_config.c

+ 4 - 4
src/test/test_config.c

@@ -193,7 +193,7 @@ test_config_check_or_create_data_subdir(void *arg)
   or_options_t *options = get_options_mutable();
   or_options_t *options = get_options_mutable();
   char *datadir = options->DataDirectory = tor_strdup(get_fname("datadir-0"));
   char *datadir = options->DataDirectory = tor_strdup(get_fname("datadir-0"));
   const char *subdir = "test_stats";
   const char *subdir = "test_stats";
-  const char *subpath = get_datadir_fname(subdir);
+  char *subpath = get_datadir_fname(subdir);
   struct stat st;
   struct stat st;
   int r;
   int r;
 #if !defined (_WIN32) || defined (WINCE)
 #if !defined (_WIN32) || defined (WINCE)
@@ -237,6 +237,7 @@ test_config_check_or_create_data_subdir(void *arg)
  done:
  done:
   rmdir(subpath);
   rmdir(subpath);
   tor_free(datadir);
   tor_free(datadir);
+  tor_free(subpath);
 }
 }
 
 
 static void
 static void
@@ -261,8 +262,7 @@ test_config_write_to_data_subdir(void *arg)
       "accusam et justo duo dolores et\n"
       "accusam et justo duo dolores et\n"
       "ea rebum. Stet clita kasd gubergren, no sea takimata\n"
       "ea rebum. Stet clita kasd gubergren, no sea takimata\n"
       "sanctus est Lorem ipsum dolor sit amet.";
       "sanctus est Lorem ipsum dolor sit amet.";
-  const char* subpath = get_datadir_fname(subdir);
-  const char* filepath = get_datadir_fname2(subdir, fname);
+  char* filepath = get_datadir_fname2(subdir, fname);
   (void)arg;
   (void)arg;
 
 
 #if defined (_WIN32) && !defined (WINCE)
 #if defined (_WIN32) && !defined (WINCE)
@@ -286,9 +286,9 @@ test_config_write_to_data_subdir(void *arg)
 
 
  done:
  done:
   remove(filepath);
   remove(filepath);
-  rmdir(subpath);
   rmdir(options->DataDirectory);
   rmdir(options->DataDirectory);
   tor_free(datadir);
   tor_free(datadir);
+  tor_free(filepath);
 }
 }
 
 
 /* Test helper function: Make sure that a bridge line gets parsed
 /* Test helper function: Make sure that a bridge line gets parsed