aboutsummaryrefslogtreecommitdiff
path: root/src/or/microdesc.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-03-31 11:57:56 -0400
committerNick Mathewson <nickm@torproject.org>2014-03-31 11:57:56 -0400
commitc0441cca8b483882f5676b98081f0fe4b52d3ae1 (patch)
tree0f6234deb72feb4de4c80ecbf4b0f0b0e89269f7 /src/or/microdesc.c
parent4ebad0d947cbb74b674468e6601894468629f814 (diff)
parent3118af2d5fca7999a94d73690d83463ddacf9acb (diff)
downloadtor-c0441cca8b483882f5676b98081f0fe4b52d3ae1.tar.gz
tor-c0441cca8b483882f5676b98081f0fe4b52d3ae1.zip
Merge branch 'bug8787_squashed'
Diffstat (limited to 'src/or/microdesc.c')
-rw-r--r--src/or/microdesc.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index 49773329c4..ec85de0d6b 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;
@@ -479,7 +486,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;
@@ -546,8 +553,14 @@ 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");
+ }
+ cache->cache_content = NULL;
+ }
if (finish_writing_to_file(open_file) < 0) {
log_warn(LD_DIR, "Error rebuilding microdescriptor cache: %s",