summaryrefslogtreecommitdiff
path: root/ares/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
commit3274908551a92d546341ce6af294fd0e0f9e25e2 (patch)
treed7b56e5957dc5d8d2c8803f27cacbba0c9ec55a1 /ares/ares_destroy.c
parentc7309344989e17b082fe8508f1d596075b847fde (diff)
downloadcurl-3274908551a92d546341ce6af294fd0e0f9e25e2.tar.gz
avoid a couple of potential zero size memory allocations
Diffstat (limited to 'ares/ares_destroy.c')
-rw-r--r--ares/ares_destroy.c42
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);
}