summaryrefslogtreecommitdiff
path: root/sample/dns-example.c
diff options
context:
space:
mode:
Diffstat (limited to 'sample/dns-example.c')
-rw-r--r--sample/dns-example.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/sample/dns-example.c b/sample/dns-example.c
index fb705664..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
@@ -154,19 +159,19 @@ main(int c, char **v) {
const char *ns;
};
struct options o;
- char opt;
+ int opt;
struct event_base *event_base = NULL;
struct evdns_base *evdns_base = NULL;
memset(&o, 0, sizeof(o));
-
+
if (c < 2) {
fprintf(stderr, "syntax: %s [-x] [-v] [-c resolv.conf] [-s ns] hostname\n", v[0]);
fprintf(stderr, "syntax: %s [-T]\n", v[0]);
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;
@@ -252,6 +257,8 @@ main(int c, char **v) {
}
fflush(stdout);
event_base_dispatch(event_base);
+ evdns_base_free(evdns_base, 1);
+ event_base_free(event_base);
return 0;
}