From 597c7b259b025080f07a68aa9be486ce3584e2d1 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 8 Jan 2015 04:43:37 +0300 Subject: [PATCH 1/3] ht-internal: don't reset hth_table_length explicitly in name_##HT_CLEAR name_##HT_CLEAR calls name_##HT_INIT that reset hth_table_length to 0. --- ht-internal.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ht-internal.h b/ht-internal.h index 8842f4cd..50375bba 100644 --- a/ht-internal.h +++ b/ht-internal.h @@ -380,7 +380,6 @@ ht_string_hash_(const char *s) { \ if (head->hth_table) \ freefn(head->hth_table); \ - head->hth_table_length = 0; \ name##_HT_INIT(head); \ } \ /* Debugging helper: return false iff the representation of 'head' is \ From 941faaed39760f0a16bd03db9fb173caaed7d877 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 8 Jan 2015 04:45:27 +0300 Subject: [PATCH 2/3] event: call event_disable_debug_mode() in libevent_global_shutdown() This will avoid leaking of event_debug_map_HT_GROW I buildin it into libevent_glboal_shutdown() because event_disable_debug_mode() -> event_free_debug_globals() -> event_free_debug_globals_locks() will clean event_debug_map_lock_ that used in event_disable_debug_mode(). --- event.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/event.c b/event.c index 2e4f64ea..909abe95 100644 --- a/event.c +++ b/event.c @@ -526,22 +526,24 @@ event_enable_debug_mode(void) #endif } -#if 0 void event_disable_debug_mode(void) { +#ifndef EVENT__DISABLE_DEBUG_MODE struct event_debug_entry **ent, *victim; EVLOCK_LOCK(event_debug_map_lock_, 0); for (ent = HT_START(event_debug_map, &global_debug_map); ent; ) { victim = *ent; - ent = HT_NEXT_RMV(event_debug_map,&global_debug_map, ent); + ent = HT_NEXT_RMV(event_debug_map, &global_debug_map, ent); mm_free(victim); } HT_CLEAR(event_debug_map, &global_debug_map); EVLOCK_UNLOCK(event_debug_map_lock_ , 0); -} + + event_debug_mode_on_ = 0; #endif +} struct event_base * event_base_new_with_config(const struct event_config *cfg) @@ -3798,6 +3800,7 @@ event_free_globals(void) void libevent_global_shutdown(void) { + event_disable_debug_mode(); event_free_globals(); } From 3540a193b5540ac72004b8f19fedf839d5cd71ad Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 8 Jan 2015 04:45:49 +0300 Subject: [PATCH 3/3] regress_dns: drop hack for event_debug_map_HT_GROW in leak tests --- test/regress_dns.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/regress_dns.c b/test/regress_dns.c index e03c143c..b91b31f1 100644 --- a/test/regress_dns.c +++ b/test/regress_dns.c @@ -1788,9 +1788,15 @@ testleak_setup(const struct testcase_t *testcase) struct testleak_env_t *env; 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); - 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. */ env = calloc(1, sizeof(struct testleak_env_t)); @@ -1811,8 +1817,8 @@ testleak_cleanup(const struct testcase_t *testcase, void *env_) #ifdef EVENT__DISABLE_DEBUG_MODE tt_int_op(allocated_chunks, ==, 0); #else - /* FIXME: that's `1' because of event_debug_map_HT_GROW */ - tt_int_op(allocated_chunks, ==, 1); + libevent_global_shutdown(); + tt_int_op(allocated_chunks, ==, 0); #endif ok = 1; end: