Skip to content

Commit

Permalink
test: fix leak in dns/getaddrinfo_cancel_stress
Browse files Browse the repository at this point in the history
Some requests may get response (evutil_addrinfo) from gaic_server_cb,
in case of cancel_event (10000ms) will not be fast enough.

(cherry picked from commit 90bcf2d)
  • Loading branch information
azat committed Jul 5, 2020
1 parent 777cc2b commit a03f0f8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/regress_dns.c
Expand Up @@ -1808,7 +1808,8 @@ struct gaic_request_status {

#define GAIC_MAGIC 0x1234abcd

static int pending = 0;
static int gaic_pending = 0;
static int gaic_freed = 0;

static void
gaic_cancel_request_cb(evutil_socket_t fd, short what, void *arg)
Expand Down Expand Up @@ -1853,7 +1854,13 @@ gaic_getaddrinfo_cb(int result, struct evutil_addrinfo *res, void *arg)
free(status);

end:
if (--pending <= 0)
if (res)
{
TT_BLATHER(("evutil_freeaddrinfo(%p)", res));
evutil_freeaddrinfo(res);
++gaic_freed;
}
if (--gaic_pending <= 0)
event_base_loopexit(base, NULL);
}

Expand All @@ -1871,7 +1878,7 @@ gaic_launch(struct event_base *base, struct evdns_base *dns_base)
"foobar.bazquux.example.com", "80", NULL, gaic_getaddrinfo_cb,
status);
event_add(&status->cancel_event, &tv);
++pending;
++gaic_pending;
}

#ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
Expand Down Expand Up @@ -2094,6 +2101,9 @@ test_getaddrinfo_async_cancel_stress(void *ptr)

event_base_dispatch(base);

// at least some was canceled via external event
tt_int_op(gaic_freed, !=, 1000);

end:
if (dns_base)
evdns_base_free(dns_base, 1);
Expand Down

0 comments on commit a03f0f8

Please sign in to comment.