]> granicus.if.org Git - libevent/commitdiff
test/dns: more graceful coverage of @fail_requests
authorAzat Khuzhin <a3at.mail@gmail.com>
Mon, 23 Nov 2015 12:14:32 +0000 (15:14 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Wed, 25 Nov 2015 10:09:01 +0000 (13:09 +0300)
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

index ecce34d15075b20134bd67c675529ff5e326ca18..a8fd301e605e2c140db45262955d6f452b9df099 100644 (file)
@@ -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;
 }