[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Always check returns from tor_munmap_file() in routerlist.c



commit 947a6daa311ebc139043fe39b775ee5928014fd6
Author: Andrea Shepard <andrea@xxxxxxxxxxxxxx>
Date:   Tue Mar 18 11:04:20 2014 -0700

    Always check returns from tor_munmap_file() in routerlist.c
---
 src/or/routerlist.c |   42 +++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 8d29b89..725718b 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -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();



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits