Always check returns from tor_munmap_file() in routerlist.c

This commit is contained in:
Andrea Shepard 2014-03-18 11:04:20 -07:00 committed by Nick Mathewson
parent 389251eda9
commit 947a6daa31

View File

@ -990,6 +990,7 @@ 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;
@ -1064,8 +1065,12 @@ router_rebuild_store(int flags, desc_store_t *store)
/* Our mmap is now invalid. */
if (store->mmap) {
tor_munmap_file(store->mmap);
store->mmap = NULL;
res = tor_munmap_file(store->mmap);
if (res == 0) {
store->mmap = NULL;
} else {
log_warn(LD_FS, "Unable to munmap route store in %s", fname);
}
}
if (replace_file(fname_tmp, fname)<0) {
@ -1136,12 +1141,21 @@ 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 */
tor_munmap_file(store->mmap);
store->mmap = NULL;
if (store->mmap) {
/* get rid of it first */
res = tor_munmap_file(store->mmap);
if (res == 0) {
store->mmap = NULL;
} else {
log_warn(LD_FS, "Failed to munmap %s", fname);
tor_free(fname);
return -1;
}
}
store->mmap = tor_mmap_file(fname);
if (store->mmap) {
@ -2782,6 +2796,8 @@ extrainfo_free_(void *e)
void
routerlist_free(routerlist_t *rl)
{
int res;
if (!rl)
return;
rimap_free(rl->identity_map, NULL);
@ -2794,10 +2810,18 @@ routerlist_free(routerlist_t *rl)
signed_descriptor_free(sd));
smartlist_free(rl->routers);
smartlist_free(rl->old_routers);
if (routerlist->desc_store.mmap)
tor_munmap_file(routerlist->desc_store.mmap);
if (routerlist->extrainfo_store.mmap)
tor_munmap_file(routerlist->extrainfo_store.mmap);
if (routerlist->desc_store.mmap) {
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);
if (res != 0) {
log_warn(LD_FS, "Failed to munmap routerlist->extrainfo_store.mmap");
}
}
tor_free(rl);
router_dir_info_changed();