From 123d372864bf95dc68061b92f5f37cc96eeb6df2 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Mon, 23 Nov 2015 15:14:32 +0300 Subject: [PATCH] test/dns: more graceful coverage of @fail_requests In case when evdns_base_free() called with @fail_requests, we can potentially have leaks, but we can avoid them if we will run event loop once again to trigger defer cbs, so let's do this, instead of magical decrements (and also this will give an example how to avoid leaks for evdns). --- test/regress_dns.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/test/regress_dns.c b/test/regress_dns.c index ecce34d1..a8fd301e 100644 --- a/test/regress_dns.c +++ b/test/regress_dns.c @@ -1902,29 +1902,22 @@ dbg_leak_resume(void *env_, int cancel, int send_err_shutdown) tt_assert(!evdns_base_resume(env->dns_base)); } + event_base_loop(env->base, EVLOOP_NONBLOCK); /** - * Because we don't cancel request, - * and want our callback to recieve DNS_ERR_SHUTDOWN, - * we use deferred callback, and there was + * Because we don't cancel request, and want our callback to recieve + * DNS_ERR_SHUTDOWN, we use deferred callback, and there was: * - one extra malloc(), * @see reply_schedule_callback() * - and one missing free * @see request_finished() (req->handle->pending_cb = 1) - * than we don't need to count in testleak_cleanup() - * - * So just decrement allocated_chunks to 2, - * like we already take care about it. + * than we don't need to count in testleak_cleanup(), but we can clean them + * if we will run loop once again, but *after* evdns base freed. */ - if (!cancel && send_err_shutdown) { - allocated_chunks -= 2; - } - - event_base_loop(env->base, EVLOOP_NONBLOCK); - -end: evdns_base_free(env->dns_base, send_err_shutdown); env->dns_base = 0; + event_base_loop(env->base, EVLOOP_NONBLOCK); +end: event_base_free(env->base); env->base = 0; } -- 2.40.0