From 07cfeb0198d9fdb59fab4f98dd780cf1c0553348 Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Sun, 22 Oct 2006 08:08:10 +0000 Subject: [PATCH] fix a minor memory leak every time we rebuild the router store, fix a rare memory leak if something goes wrong while rebuilding it, and clean up some code. nick, please confirm. reported by "fookoowa" in flyspray 346 (yay!) svn:r8789 --- src/or/routerlist.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 9e4fce4372..f63d41f7a8 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -265,12 +265,8 @@ router_rebuild_store(int force) smartlist_add_all(routers, routerlist->routers); smartlist_sort(routers, _compare_routers_by_age); for (i = 0; i < 2; ++i) { - smartlist_t *lst = smartlist_create(); /* We sort the routers by age to enhance locality on disk. */ - if (i==0) - lst = old_routers; - else - lst = routers; + smartlist_t *lst = (i == 0) ? old_routers : routers; /* Now, add the appropriate members to chunk_list */ SMARTLIST_FOREACH(lst, void *, ptr, { @@ -280,7 +276,6 @@ router_rebuild_store(int force) const char *body = signed_descriptor_get_body(sd); if (!body) { log_warn(LD_BUG, "Bug! No descriptor available for router."); - smartlist_free(lst); goto done; } c = tor_malloc(sizeof(sized_chunk_t)); @@ -318,8 +313,6 @@ router_rebuild_store(int force) signed_descriptor_get_body(sd); }); } - smartlist_free(old_routers); - smartlist_free(routers); tor_snprintf(fname, fname_len, "%s/cached-routers.new", options->DataDirectory); @@ -331,11 +324,11 @@ router_rebuild_store(int force) router_journal_len = 0; router_bytes_dropped = 0; done: + smartlist_free(old_routers); + smartlist_free(routers); tor_free(fname); - if (chunk_list) { - SMARTLIST_FOREACH(chunk_list, sized_chunk_t *, c, tor_free(c)); - smartlist_free(chunk_list); - } + SMARTLIST_FOREACH(chunk_list, sized_chunk_t *, c, tor_free(c)); + smartlist_free(chunk_list); return r; }