aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-06-30 16:37:08 +0000
committerNick Mathewson <nickm@torproject.org>2004-06-30 16:37:08 +0000
commitb1e9adf05612959b20da5f8078a7e2edf27b4e74 (patch)
tree5c6ba98675dcc38d84da609736c7b3de08f264bd /src/or
parent653aaeef08764b80820f87b916f5833f64f9ebbe (diff)
downloadtor-b1e9adf05612959b20da5f8078a7e2edf27b4e74.tar
tor-b1e9adf05612959b20da5f8078a7e2edf27b4e74.tar.gz
Always use get_data_directory() instead of options.DataDirectory; fix a memory leak in router.c
svn:r1991
Diffstat (limited to 'src/or')
-rw-r--r--src/or/dirserv.c4
-rw-r--r--src/or/main.c6
-rw-r--r--src/or/router.c24
3 files changed, 18 insertions, 16 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 6e09ee1ec..8252ee077 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -597,7 +597,7 @@ void dirserv_set_cached_directory(const char *directory, time_t when)
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 @@ size_t dirserv_get_directory(const char **directory)
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.");
}
diff --git a/src/or/main.c b/src/or/main.c
index 99e83f37c..9aba9cffe 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -586,7 +586,7 @@ static int init_from_config(int argc, char **argv) {
/* 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 @@ static int do_hup(void) {
}
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 @@ static int do_hup(void) {
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;
diff --git a/src/or/router.c b/src/or/router.c
index 9d386bbad..26b8d89e1 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -98,7 +98,7 @@ void rotate_onion_key(void)
{
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 @@ int init_keys(void) {
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 @@ int init_keys(void) {
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 @@ int init_keys(void) {
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 @@ int init_keys(void) {
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 @@ int init_keys(void) {
} 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;