[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] clean up memory leaks, confusions
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
routers.c
Log Message:
clean up memory leaks, confusions
still one memory leak remaining here.
Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- routers.c 17 Oct 2003 04:48:20 -0000 1.80
+++ routers.c 18 Oct 2003 02:18:22 -0000 1.81
@@ -32,7 +32,6 @@
static char *eat_whitespace(char *s);
static char *eat_whitespace_no_nl(char *s);
static char *find_whitespace(char *s);
-static void router_free_exit_policy(routerinfo_t *router);
static int router_add_exit_policy_from_string(routerinfo_t *router, char *s);
static int router_add_exit_policy(routerinfo_t *router,
directory_token_t *tok);
@@ -137,44 +136,45 @@
*pdirectory = directory;
}
-/* delete a list of routers from memory */
+/* delete a router from memory */
void routerinfo_free(routerinfo_t *router)
{
- struct exit_policy_t *e = NULL, *etmp = NULL;
+ struct exit_policy_t *e;
if (!router)
return;
if (router->address)
free(router->address);
+ if (router->nickname)
+ free(router->nickname);
if (router->onion_pkey)
crypto_free_pk_env(router->onion_pkey);
if (router->link_pkey)
crypto_free_pk_env(router->link_pkey);
if (router->identity_pkey)
crypto_free_pk_env(router->identity_pkey);
- e = router->exit_policy;
- while (e) {
- etmp = e->next;
+ while (router->exit_policy) {
+ e = router->exit_policy;
+ router->exit_policy = e->next;
if (e->string) free(e->string);
if (e->address) free(e->address);
if (e->port) free(e->port);
free(e);
- e = etmp;
}
free(router);
}
-void directory_free(directory_t *directory)
+void directory_free(directory_t *dir)
{
int i;
- for (i = 0; i < directory->n_routers; ++i)
- routerinfo_free(directory->routers[i]);
- if (directory->routers)
- free(directory->routers);
- if(directory->software_versions)
- free(directory->software_versions);
- free(directory);
+ for (i = 0; i < dir->n_routers; ++i)
+ routerinfo_free(dir->routers[i]);
+ if (dir->routers)
+ free(dir->routers);
+ if(dir->software_versions)
+ free(dir->software_versions);
+ free(dir);
}
void router_mark_as_down(char *nickname) {
@@ -681,6 +681,9 @@
router = router_get_entry_from_string(s);
if (!router) {
log_fn(LOG_WARN, "Error reading router");
+ for(i=0;i<rarray_len;i++)
+ routerinfo_free(rarray[i]);
+ free(rarray);
return -1;
}
if (rarray_len >= MAX_ROUTERS_IN_DIR) {
@@ -794,8 +797,6 @@
router = tor_malloc(sizeof(routerinfo_t));
memset(router,0,sizeof(routerinfo_t)); /* zero it out first */
- /* C doesn't guarantee that NULL is represented by 0 bytes. You'll
- thank me for this someday. */
router->onion_pkey = router->identity_pkey = router->link_pkey = NULL;
if (tok->val.cmd.n_args != 6) {
@@ -919,34 +920,12 @@
err:
router_release_token(tok);
- if(router->address)
- free(router->address);
- if(router->link_pkey)
- crypto_free_pk_env(router->link_pkey);
- if(router->onion_pkey)
- crypto_free_pk_env(router->onion_pkey);
- if(router->identity_pkey)
- crypto_free_pk_env(router->identity_pkey);
- router_free_exit_policy(router);
- free(router);
+ routerinfo_free(router);
return NULL;
#undef ARGS
#undef NEXT_TOKEN
}
-static void router_free_exit_policy(routerinfo_t *router) {
- struct exit_policy_t *tmpe;
-
- while(router->exit_policy) {
- tmpe = router->exit_policy;
- router->exit_policy = tmpe->next;
- free(tmpe->string);
- free(tmpe->address);
- free(tmpe->port);
- free(tmpe);
- }
-}
-
void router_add_exit_policy_from_config(routerinfo_t *router) {
char *s = options.ExitPolicy, *e;
int last=0;
@@ -1132,6 +1111,7 @@
address = localhostname;
if(!strchr(address,'.')) {
log_fn(LOG_WARN,"fqdn '%s' has only one element. Misconfigured machine?",address);
+ log_fn(LOG_WARN,"Try setting the Address line in your config file.");
return -1;
}
}