mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
Always check returns from tor_munmap_file() in microdesc.c
This commit is contained in:
parent
947a6daa31
commit
df076eccfa
@ -275,6 +275,7 @@ void
|
|||||||
microdesc_cache_clear(microdesc_cache_t *cache)
|
microdesc_cache_clear(microdesc_cache_t *cache)
|
||||||
{
|
{
|
||||||
microdesc_t **entry, **next;
|
microdesc_t **entry, **next;
|
||||||
|
|
||||||
for (entry = HT_START(microdesc_map, &cache->map); entry; entry = next) {
|
for (entry = HT_START(microdesc_map, &cache->map); entry; entry = next) {
|
||||||
microdesc_t *md = *entry;
|
microdesc_t *md = *entry;
|
||||||
next = HT_NEXT_RMV(microdesc_map, &cache->map, 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);
|
HT_CLEAR(microdesc_map, &cache->map);
|
||||||
if (cache->cache_content) {
|
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->cache_content = NULL;
|
||||||
}
|
}
|
||||||
cache->total_len_seen = 0;
|
cache->total_len_seen = 0;
|
||||||
@ -429,7 +436,7 @@ int
|
|||||||
microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
|
microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
|
||||||
{
|
{
|
||||||
open_file_t *open_file;
|
open_file_t *open_file;
|
||||||
int fd = -1;
|
int fd = -1, res;
|
||||||
microdesc_t **mdp;
|
microdesc_t **mdp;
|
||||||
smartlist_t *wrote;
|
smartlist_t *wrote;
|
||||||
ssize_t size;
|
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
|
/* We must do this unmap _before_ we call finish_writing_to_file(), or
|
||||||
* windows will not actually replace the file. */
|
* windows will not actually replace the file. */
|
||||||
if (cache->cache_content)
|
if (cache->cache_content) {
|
||||||
tor_munmap_file(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) {
|
if (finish_writing_to_file(open_file) < 0) {
|
||||||
log_warn(LD_DIR, "Error rebuilding microdescriptor cache: %s",
|
log_warn(LD_DIR, "Error rebuilding microdescriptor cache: %s",
|
||||||
|
@ -990,7 +990,6 @@ router_rebuild_store(int flags, desc_store_t *store)
|
|||||||
size_t total_expected_len = 0;
|
size_t total_expected_len = 0;
|
||||||
int had_any;
|
int had_any;
|
||||||
int force = flags & RRS_FORCE;
|
int force = flags & RRS_FORCE;
|
||||||
int res;
|
|
||||||
|
|
||||||
if (!force && !router_should_rebuild_store(store)) {
|
if (!force && !router_should_rebuild_store(store)) {
|
||||||
r = 0;
|
r = 0;
|
||||||
@ -1065,10 +1064,9 @@ router_rebuild_store(int flags, desc_store_t *store)
|
|||||||
|
|
||||||
/* Our mmap is now invalid. */
|
/* Our mmap is now invalid. */
|
||||||
if (store->mmap) {
|
if (store->mmap) {
|
||||||
res = tor_munmap_file(store->mmap);
|
int res = tor_munmap_file(store->mmap);
|
||||||
if (res == 0) {
|
|
||||||
store->mmap = NULL;
|
store->mmap = NULL;
|
||||||
} else {
|
if (res != 0) {
|
||||||
log_warn(LD_FS, "Unable to munmap route store in %s", fname);
|
log_warn(LD_FS, "Unable to munmap route store in %s", fname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1141,16 +1139,14 @@ router_reload_router_list_impl(desc_store_t *store)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
int extrainfo = (store->type == EXTRAINFO_STORE);
|
int extrainfo = (store->type == EXTRAINFO_STORE);
|
||||||
store->journal_len = store->store_len = 0;
|
store->journal_len = store->store_len = 0;
|
||||||
int res;
|
|
||||||
|
|
||||||
fname = get_datadir_fname(store->fname_base);
|
fname = get_datadir_fname(store->fname_base);
|
||||||
|
|
||||||
if (store->mmap) {
|
if (store->mmap) {
|
||||||
/* get rid of it first */
|
/* get rid of it first */
|
||||||
res = tor_munmap_file(store->mmap);
|
int res = tor_munmap_file(store->mmap);
|
||||||
if (res == 0) {
|
|
||||||
store->mmap = NULL;
|
store->mmap = NULL;
|
||||||
} else {
|
if (res != 0) {
|
||||||
log_warn(LD_FS, "Failed to munmap %s", fname);
|
log_warn(LD_FS, "Failed to munmap %s", fname);
|
||||||
tor_free(fname);
|
tor_free(fname);
|
||||||
return -1;
|
return -1;
|
||||||
@ -2796,8 +2792,6 @@ extrainfo_free_(void *e)
|
|||||||
void
|
void
|
||||||
routerlist_free(routerlist_t *rl)
|
routerlist_free(routerlist_t *rl)
|
||||||
{
|
{
|
||||||
int res;
|
|
||||||
|
|
||||||
if (!rl)
|
if (!rl)
|
||||||
return;
|
return;
|
||||||
rimap_free(rl->identity_map, NULL);
|
rimap_free(rl->identity_map, NULL);
|
||||||
@ -2811,13 +2805,13 @@ routerlist_free(routerlist_t *rl)
|
|||||||
smartlist_free(rl->routers);
|
smartlist_free(rl->routers);
|
||||||
smartlist_free(rl->old_routers);
|
smartlist_free(rl->old_routers);
|
||||||
if (routerlist->desc_store.mmap) {
|
if (routerlist->desc_store.mmap) {
|
||||||
res = tor_munmap_file(routerlist->desc_store.mmap);
|
int res = tor_munmap_file(routerlist->desc_store.mmap);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
log_warn(LD_FS, "Failed to munmap routerlist->desc_store.mmap");
|
log_warn(LD_FS, "Failed to munmap routerlist->desc_store.mmap");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (routerlist->extrainfo_store.mmap) {
|
if (routerlist->extrainfo_store.mmap) {
|
||||||
res = tor_munmap_file(routerlist->extrainfo_store.mmap);
|
int res = tor_munmap_file(routerlist->extrainfo_store.mmap);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
log_warn(LD_FS, "Failed to munmap routerlist->extrainfo_store.mmap");
|
log_warn(LD_FS, "Failed to munmap routerlist->extrainfo_store.mmap");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user