diff options
Diffstat (limited to 'ares/ares_destroy.c')
-rw-r--r-- | ares/ares_destroy.c | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/ares/ares_destroy.c b/ares/ares_destroy.c index b7a21e9e3..fd243c30a 100644 --- a/ares/ares_destroy.c +++ b/ares/ares_destroy.c @@ -25,23 +25,37 @@ void ares_destroy(ares_channel channel) int i; struct query *query; - for (i = 0; i < channel->nservers; i++) - ares__close_sockets(channel, &channel->servers[i]); - free(channel->servers); - for (i = 0; i < channel->ndomains; i++) - free(channel->domains[i]); - free(channel->domains); + if (!channel) + return; + + if (channel->servers) { + for (i = 0; i < channel->nservers; i++) + ares__close_sockets(channel, &channel->servers[i]); + free(channel->servers); + } + + if (channel->domains) { + for (i = 0; i < channel->ndomains; i++) + free(channel->domains[i]); + free(channel->domains); + } + if(channel->sortlist) free(channel->sortlist); - free(channel->lookups); - while (channel->queries) - { - query = channel->queries; - channel->queries = query->next; - query->callback(query->arg, ARES_EDESTRUCTION, NULL, 0); + + if (channel->lookups) + free(channel->lookups); + + while (channel->queries) { + query = channel->queries; + channel->queries = query->next; + query->callback(query->arg, ARES_EDESTRUCTION, NULL, 0); + if (query->tcpbuf) free(query->tcpbuf); + if (query->skip_server) free(query->skip_server); - free(query); - } + free(query); + } + free(channel); } |