From df076eccfaa680ee08b8ae866690d9a2a8ba5555 Mon Sep 17 00:00:00 2001 From: Andrea Shepard Date: Tue, 18 Mar 2014 12:39:02 -0700 Subject: Always check returns from tor_munmap_file() in microdesc.c --- src/or/microdesc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/or/microdesc.c') diff --git a/src/or/microdesc.c b/src/or/microdesc.c index 6419ea79f8..f196536da7 100644 --- a/src/or/microdesc.c +++ b/src/or/microdesc.c @@ -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", -- cgit v1.2.3-54-g00ecf From 449b87791d5a9f15c63b39e0ff36f8ba89676c6c Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 31 Mar 2014 11:42:49 -0400 Subject: NULL out all mappings after tor_munmap_file() --- src/or/microdesc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/or/microdesc.c') diff --git a/src/or/microdesc.c b/src/or/microdesc.c index f196536da7..9c91f17a6e 100644 --- a/src/or/microdesc.c +++ b/src/or/microdesc.c @@ -509,6 +509,7 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force) log_warn(LD_FS, "Failed to unmap old microdescriptor cache while rebuilding"); } + cache->cache_content = NULL; } if (finish_writing_to_file(open_file) < 0) { -- cgit v1.2.3-54-g00ecf