Merge pull request #207 from azat/avoid-leaking-of-event_debug_map_HT_GROW

Avoid leaking of event_debug_map_HT_GROW
This commit is contained in:
Nick Mathewson 2015-02-04 08:33:42 -05:00
commit 51821e20b2
3 changed files with 16 additions and 8 deletions

View File

@ -526,10 +526,10 @@ event_enable_debug_mode(void)
#endif #endif
} }
#if 0
void void
event_disable_debug_mode(void) event_disable_debug_mode(void)
{ {
#ifndef EVENT__DISABLE_DEBUG_MODE
struct event_debug_entry **ent, *victim; struct event_debug_entry **ent, *victim;
EVLOCK_LOCK(event_debug_map_lock_, 0); EVLOCK_LOCK(event_debug_map_lock_, 0);
@ -540,8 +540,10 @@ event_disable_debug_mode(void)
} }
HT_CLEAR(event_debug_map, &global_debug_map); HT_CLEAR(event_debug_map, &global_debug_map);
EVLOCK_UNLOCK(event_debug_map_lock_ , 0); EVLOCK_UNLOCK(event_debug_map_lock_ , 0);
}
event_debug_mode_on_ = 0;
#endif #endif
}
struct event_base * struct event_base *
event_base_new_with_config(const struct event_config *cfg) event_base_new_with_config(const struct event_config *cfg)
@ -3798,6 +3800,7 @@ event_free_globals(void)
void void
libevent_global_shutdown(void) libevent_global_shutdown(void)
{ {
event_disable_debug_mode();
event_free_globals(); event_free_globals();
} }

View File

@ -380,7 +380,6 @@ ht_string_hash_(const char *s)
{ \ { \
if (head->hth_table) \ if (head->hth_table) \
freefn(head->hth_table); \ freefn(head->hth_table); \
head->hth_table_length = 0; \
name##_HT_INIT(head); \ name##_HT_INIT(head); \
} \ } \
/* Debugging helper: return false iff the representation of 'head' is \ /* Debugging helper: return false iff the representation of 'head' is \

View File

@ -1804,8 +1804,14 @@ testleak_setup(const struct testcase_t *testcase)
struct testleak_env_t *env; struct testleak_env_t *env;
allocated_chunks = 0; allocated_chunks = 0;
/* Reset allocation counter, to start allocations from the very beginning.
* (this will avoid false-positive negative numbers for allocated_chunks)
*/
libevent_global_shutdown();
event_set_mem_functions(cnt_malloc, cnt_realloc, cnt_free); event_set_mem_functions(cnt_malloc, cnt_realloc, cnt_free);
if (!libevent_tests_running_in_debug_mode)
event_enable_debug_mode(); event_enable_debug_mode();
/* not mm_calloc: we don't want to mess with the count. */ /* not mm_calloc: we don't want to mess with the count. */
@ -1827,8 +1833,8 @@ testleak_cleanup(const struct testcase_t *testcase, void *env_)
#ifdef EVENT__DISABLE_DEBUG_MODE #ifdef EVENT__DISABLE_DEBUG_MODE
tt_int_op(allocated_chunks, ==, 0); tt_int_op(allocated_chunks, ==, 0);
#else #else
/* FIXME: that's `1' because of event_debug_map_HT_GROW */ libevent_global_shutdown();
tt_int_op(allocated_chunks, ==, 1); tt_int_op(allocated_chunks, ==, 0);
#endif #endif
ok = 1; ok = 1;
end: end: