From d0cde45477c69fb7987115e6fc2d34fa9a2b7db2 Mon Sep 17 00:00:00 2001 From: Bogdan Harjoc Date: Thu, 9 Aug 2018 14:47:17 +0300 Subject: [PATCH] dns-example: free result in getaddrinfo callback According to evdns.c, the result not freed by libevent after the callback runs: evdns_getaddrinfo_gotresolve() { ... data->user_cb(0, data->pending_result, data->user_data); data->pending_result = NULL; ... } To reproduce, build with -fsanitize=address, add -g to the getopt list in dns-example.c like in the current commit and run dns-example -g google.com Closes: #681 # cherry-picked (cherry picked from commit 855f0804305a545da6880850d16809969ce72edd) --- sample/dns-example.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sample/dns-example.c b/sample/dns-example.c index 6243458a..21a75de8 100644 --- a/sample/dns-example.c +++ b/sample/dns-example.c @@ -78,6 +78,8 @@ gai_callback(int err, struct evutil_addrinfo *ai, void *arg) { const char *name = arg; int i; + struct evutil_addrinfo *first_ai = ai; + if (err) { printf("%s: %s\n", name, evutil_gai_strerror(err)); } @@ -99,6 +101,9 @@ gai_callback(int err, struct evutil_addrinfo *ai, void *arg) printf("[%d] %s: %s\n",i,name,buf); } } + + if (first_ai) + evutil_freeaddrinfo(first_ai); } static void @@ -166,7 +171,7 @@ main(int c, char **v) { return 1; } - while ((opt = getopt(c, v, "xvc:Ts:")) != -1) { + while ((opt = getopt(c, v, "xvc:Ts:g")) != -1) { switch (opt) { case 'x': o.reverse = 1; break; case 'v': ++verbose; break; -- 2.50.1