[or-cvs] Always use get_data_directory() instead of options.DataDire...

Nick Mathewson nickm at seul.org
Wed Jun 30 16:37:10 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv23485/src/or

Modified Files:
	dirserv.c main.c router.c 
Log Message:
Always use get_data_directory() instead of options.DataDirectory; fix a memory leak in router.c

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- dirserv.c	25 Jun 2004 00:29:30 -0000	1.55
+++ dirserv.c	30 Jun 2004 16:37:08 -0000	1.56
@@ -597,7 +597,7 @@
     cached_directory = tor_strdup(directory);
     cached_directory_len = strlen(cached_directory);
     cached_directory_published = when;
-    sprintf(filename,"%s/cached-directory", options.DataDirectory);
+    sprintf(filename,"%s/cached-directory", get_data_directory(&options));
     if(write_str_to_file(filename,cached_directory) < 0) {
       log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring.");
     }
@@ -643,7 +643,7 @@
       exit(0);
     }
     free(new_directory);
-    sprintf(filename,"%s/cached-directory", options.DataDirectory);
+    sprintf(filename,"%s/cached-directory", get_data_directory(&options));
     if(write_str_to_file(filename,the_directory) < 0) {
       log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring.");
     }

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.285
retrieving revision 1.286
diff -u -d -r1.285 -r1.286
--- main.c	25 Jun 2004 00:29:30 -0000	1.285
+++ main.c	30 Jun 2004 16:37:08 -0000	1.286
@@ -586,7 +586,7 @@
 
   /* Start backgrounding the process, if requested. */
   if (options.RunAsDaemon) {
-    start_daemon(options.DataDirectory);
+    start_daemon(get_data_directory(&options));
   }
 
   /* Configure the log(s) */
@@ -638,7 +638,7 @@
   }
   if(options.DirPort) {
     /* reload the approved-routers file */
-    sprintf(keydir,"%s/approved-routers", options.DataDirectory);
+    sprintf(keydir,"%s/approved-routers", get_data_directory(&options));
     log_fn(LOG_INFO,"Reloading approved fingerprints from %s...",keydir);
     if(dirserv_parse_fingerprint_file(keydir) < 0) {
       log_fn(LOG_WARN, "Error reloading fingerprints. Continuing with old list.");
@@ -657,7 +657,7 @@
     dnsworkers_rotate();
     /* Rebuild fresh descriptor as needed. */
     router_rebuild_descriptor();
-    sprintf(keydir,"%s/router.desc", options.DataDirectory);
+    sprintf(keydir,"%s/router.desc", get_data_directory(&options));
     log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir);
     if (write_str_to_file(keydir, router_get_my_descriptor())) {
       return -1;

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- router.c	25 Jun 2004 00:29:31 -0000	1.51
+++ router.c	30 Jun 2004 16:37:08 -0000	1.52
@@ -98,7 +98,7 @@
 {
   char fname[512];
   crypto_pk_env_t *prkey;
-  sprintf(fname,"%s/keys/onion.key",options.DataDirectory);
+  sprintf(fname,"%s/keys/onion.key",get_data_directory(&options));
   if (!(prkey = crypto_new_pk_env())) {
     log(LOG_ERR, "Error creating crypto environment.");
     goto error;
@@ -183,7 +183,7 @@
   char keydir[512];
   char fingerprint[FINGERPRINT_LEN+MAX_NICKNAME_LEN+3];
   char *cp;
-  const char *tmp, *mydesc;
+  const char *tmp, *mydesc, *datadir;
   crypto_pk_env_t *prkey;
 
   if (!key_lock)
@@ -199,16 +199,17 @@
     return 0;
   }
   /* Make sure DataDirectory exists, and is private. */
-  tor_assert(options.DataDirectory);
-  if (strlen(options.DataDirectory) > (512-128)) {
+  datadir = get_data_directory(&options);
+  tor_assert(datadir);
+  if (strlen(datadir) > (512-128)) {
     log_fn(LOG_ERR, "DataDirectory is too long.");
     return -1;
   }
-  if (check_private_dir(options.DataDirectory, 1)) {
+  if (check_private_dir(datadir, 1)) {
     return -1;
   }
   /* Check the key directory. */
-  sprintf(keydir,"%s/keys",options.DataDirectory);
+  sprintf(keydir,"%s/keys", datadir);
   if (check_private_dir(keydir, 1)) {
     return -1;
   }
@@ -249,13 +250,13 @@
     log(LOG_ERR, "Unable to add own descriptor to directory.");
     return -1;
   }
-  sprintf(keydir,"%s/router.desc", options.DataDirectory);
+  sprintf(keydir,"%s/router.desc", datadir);
   log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir);
   if (write_str_to_file(keydir, mydesc)) {
     return -1;
   }
   /* 5. Dump fingerprint to 'fingerprint' */
-  sprintf(keydir,"%s/fingerprint", options.DataDirectory);
+  sprintf(keydir,"%s/fingerprint", datadir);
   log_fn(LOG_INFO,"Dumping fingerprint to %s...",keydir);
   tor_assert(strlen(options.Nickname) <= MAX_NICKNAME_LEN);
   strcpy(fingerprint, options.Nickname);
@@ -271,14 +272,14 @@
   if(!options.DirPort)
     return 0;
   /* 6. [dirserver only] load approved-routers file */
-  sprintf(keydir,"%s/approved-routers", options.DataDirectory);
+  sprintf(keydir,"%s/approved-routers", datadir);
   log_fn(LOG_INFO,"Loading approved fingerprints from %s...",keydir);
   if(dirserv_parse_fingerprint_file(keydir) < 0) {
     log_fn(LOG_ERR, "Error loading fingerprints");
     return -1;
   }
   /* 7. [dirserver only] load old directory, if it's there */
-  sprintf(keydir,"%s/cached-directory", options.DataDirectory);
+  sprintf(keydir,"%s/cached-directory", datadir);
   log_fn(LOG_INFO,"Loading cached directory from %s...",keydir);
   cp = read_file_to_str(keydir);
   if(!cp) {
@@ -286,12 +287,13 @@
   } else {
     if(options.AuthoritativeDir && dirserv_load_from_directory_string(cp) < 0){
       log_fn(LOG_ERR, "Cached directory %s is corrupt", keydir);
-      free(cp);
+      tor_free(cp);
       return -1;
     }
     /* set time to 1 so it will be replaced on first download.
      */
     dirserv_set_cached_directory(cp, 1);
+    tor_free(cp);
   }
   /* success */
   return 0;



More information about the tor-commits mailing list