diff options
author | Andrea Shepard <andrea@torproject.org> | 2014-03-18 12:39:02 -0700 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-03-31 11:27:08 -0400 |
commit | df076eccfaa680ee08b8ae866690d9a2a8ba5555 (patch) | |
tree | 3582108d0c51521493b1d637cfa781078cf09548 /src/or/microdesc.c | |
parent | 947a6daa311ebc139043fe39b775ee5928014fd6 (diff) | |
download | tor-df076eccfaa680ee08b8ae866690d9a2a8ba5555.tar.gz tor-df076eccfaa680ee08b8ae866690d9a2a8ba5555.zip |
Always check returns from tor_munmap_file() in microdesc.c
Diffstat (limited to 'src/or/microdesc.c')
-rw-r--r-- | src/or/microdesc.c | 20 |
1 files changed, 16 insertions, 4 deletions
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", |