summaryrefslogtreecommitdiff
path: root/ares_destroy.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2006-11-06 13:56:51 +0000
committerYang Tse <yangsita@gmail.com>2006-11-06 13:56:51 +0000
commit877966659d757864850695fae1a87f30aa65cc9c (patch)
treef4d451a515f42afc8ea22c8f95fe10d362f744df /ares_destroy.c
parentfadf4bfa08746bd23ec838ab69edcc3b41e6f512 (diff)
downloadc-ares-877966659d757864850695fae1a87f30aa65cc9c.tar.gz
c-ares-877966659d757864850695fae1a87f30aa65cc9c.tar.bz2
c-ares-877966659d757864850695fae1a87f30aa65cc9c.zip
avoid a couple of potential zero size memory allocations
Diffstat (limited to 'ares_destroy.c')
-rw-r--r--ares_destroy.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/ares_destroy.c b/ares_destroy.c
index b7a21e9..fd243c3 100644
--- a/ares_destroy.c
+++ b/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);
}