Always check returns from tor_munmap_file() in microdesc.c

This commit is contained in:
Andrea Shepard 2014-03-18 12:39:02 -07:00 committed by Nick Mathewson
parent 947a6daa31
commit df076eccfa
2 changed files with 24 additions and 18 deletions

View File

@ -275,6 +275,7 @@ void
microdesc_cache_clear(microdesc_cache_t *cache)
{
microdesc_t **entry, **next;
for (entry = HT_START(microdesc_map, &cache->map); entry; entry = next) {
microdesc_t *md = *entry;
next = HT_NEXT_RMV(microdesc_map, &cache->map, entry);
@ -283,7 +284,13 @@ microdesc_cache_clear(microdesc_cache_t *cache)
}
HT_CLEAR(microdesc_map, &cache->map);
if (cache->cache_content) {
tor_munmap_file(cache->cache_content);
int res = tor_munmap_file(cache->cache_content);
if (res != 0) {
log_warn(LD_FS,
"tor_munmap_file() failed clearing microdesc cache; "
"we are probably about to leak memory.");
/* TODO something smarter? */
}
cache->cache_content = NULL;
}
cache->total_len_seen = 0;
@ -429,7 +436,7 @@ int
microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
{
open_file_t *open_file;
int fd = -1;
int fd = -1, res;
microdesc_t **mdp;
smartlist_t *wrote;
ssize_t size;
@ -496,8 +503,13 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
/* We must do this unmap _before_ we call finish_writing_to_file(), or
* windows will not actually replace the file. */
if (cache->cache_content)
tor_munmap_file(cache->cache_content);
if (cache->cache_content) {
res = tor_munmap_file(cache->cache_content);
if (res != 0) {
log_warn(LD_FS,
"Failed to unmap old microdescriptor cache while rebuilding");
}
}
if (finish_writing_to_file(open_file) < 0) {
log_warn(LD_DIR, "Error rebuilding microdescriptor cache: %s",

View File

@ -990,7 +990,6 @@ router_rebuild_store(int flags, desc_store_t *store)
size_t total_expected_len = 0;
int had_any;
int force = flags & RRS_FORCE;
int res;
if (!force && !router_should_rebuild_store(store)) {
r = 0;
@ -1065,10 +1064,9 @@ router_rebuild_store(int flags, desc_store_t *store)
/* Our mmap is now invalid. */
if (store->mmap) {
res = tor_munmap_file(store->mmap);
if (res == 0) {
store->mmap = NULL;
} else {
int res = tor_munmap_file(store->mmap);
store->mmap = NULL;
if (res != 0) {
log_warn(LD_FS, "Unable to munmap route store in %s", fname);
}
}
@ -1141,16 +1139,14 @@ router_reload_router_list_impl(desc_store_t *store)
struct stat st;
int extrainfo = (store->type == EXTRAINFO_STORE);
store->journal_len = store->store_len = 0;
int res;
fname = get_datadir_fname(store->fname_base);
if (store->mmap) {
/* get rid of it first */
res = tor_munmap_file(store->mmap);
if (res == 0) {
store->mmap = NULL;
} else {
int res = tor_munmap_file(store->mmap);
store->mmap = NULL;
if (res != 0) {
log_warn(LD_FS, "Failed to munmap %s", fname);
tor_free(fname);
return -1;
@ -2796,8 +2792,6 @@ extrainfo_free_(void *e)
void
routerlist_free(routerlist_t *rl)
{
int res;
if (!rl)
return;
rimap_free(rl->identity_map, NULL);
@ -2811,13 +2805,13 @@ routerlist_free(routerlist_t *rl)
smartlist_free(rl->routers);
smartlist_free(rl->old_routers);
if (routerlist->desc_store.mmap) {
res = tor_munmap_file(routerlist->desc_store.mmap);
int res = tor_munmap_file(routerlist->desc_store.mmap);
if (res != 0) {
log_warn(LD_FS, "Failed to munmap routerlist->desc_store.mmap");
}
}
if (routerlist->extrainfo_store.mmap) {
res = tor_munmap_file(routerlist->extrainfo_store.mmap);
int res = tor_munmap_file(routerlist->extrainfo_store.mmap);
if (res != 0) {
log_warn(LD_FS, "Failed to munmap routerlist->extrainfo_store.mmap");
}