diff options
author | Daniel Stenberg <daniel@haxx.se> | 2011-12-23 14:30:43 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2011-12-23 14:46:20 +0100 |
commit | 2caa454dc19237588ee3696fac2d74fb86eb0d98 (patch) | |
tree | b1e56cc99e09a8edb671400d930a63050e280d4c /lib/hostip.c | |
parent | 3e4181f88ef170ed902db035797d02cea1bcc2ec (diff) | |
download | curl-2caa454dc19237588ee3696fac2d74fb86eb0d98.tar.gz |
resolve: don't leak pre-populated dns entries
CURLOPT_RESOLVE populates the DNS cache with entries that are marked as
eternally in use. Those entries need to be taken care of when the cache
is killed off.
Bug: http://curl.haxx.se/bug/view.cgi?id=3463121
Reported by: "tw84452852"
Diffstat (limited to 'lib/hostip.c')
-rw-r--r-- | lib/hostip.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/hostip.c b/lib/hostip.c index d261a163a..44ed0a424 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -721,4 +721,25 @@ struct curl_hash *Curl_mk_dnscache(void) return Curl_hash_alloc(7, Curl_hash_str, Curl_str_key_compare, freednsentry); } +static int hostcache_inuse(void *data, void *hc) +{ + struct Curl_dns_entry *c = (struct Curl_dns_entry *) hc; + + if(c->inuse == 1) + Curl_resolv_unlock(data, c); + + return 1; /* free all entries */ +} +void Curl_hostcache_destroy(struct SessionHandle *data) +{ + /* Entries added to the hostcache with the CURLOPT_RESOLVE function are + * still present in the cache with the inuse counter set to 1. Detect them + * and cleanup! + */ + Curl_hash_clean_with_criterium(data->dns.hostcache, data, hostcache_inuse); + + Curl_hash_destroy(data->dns.hostcache); + data->dns.hostcachetype = HCACHE_NONE; + data->dns.hostcache = NULL; +} |