summaryrefslogtreecommitdiff
path: root/lib/hostip.c
diff options
context:
space:
mode:
authorAlibek.Jorajev <ajorajev@blackberry.com>2018-05-30 15:23:35 +0100
committerDaniel Stenberg <daniel@haxx.se>2018-06-01 12:47:52 +0200
commitf66d97b677d114733f6b938d54ce7502d6aff214 (patch)
tree6727cfc6ce56762771a85a44f5061f968adc0784 /lib/hostip.c
parenta115c6bbe73175ad6157fce67338d4a18ed768b2 (diff)
downloadcurl-f66d97b677d114733f6b938d54ce7502d6aff214.tar.gz
CURLOPT_RESOLVE: always purge old entry first
If there's an existing entry using the selected name. Closes #2622
Diffstat (limited to 'lib/hostip.c')
-rw-r--r--lib/hostip.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/hostip.c b/lib/hostip.c
index c2f9defd9..d809578e1 100644
--- a/lib/hostip.c
+++ b/lib/hostip.c
@@ -1010,24 +1010,28 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data)
/* See if its already in our dns cache */
dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1);
+ if(dns) {
+ infof(data, "RESOLVE %s:%d is - old addresses discarded!\n",
+ hostname, port);
+ /* delete old entry entry, there are two reasons for this
+ 1. old entry may have different addresses.
+ 2. even if entry with correct addresses is already in the cache,
+ but if it is close to expire, then by the time next http
+ request is made, it can get expired and pruned because old
+ entry is not necessarily marked as added by CURLOPT_RESOLVE. */
+
+ Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1);
+ }
/* free the allocated entry_id again */
free(entry_id);
- if(!dns) {
- /* if not in the cache already, put this host in the cache */
- dns = Curl_cache_addr(data, head, hostname, port);
- if(dns) {
- dns->timestamp = 0; /* mark as added by CURLOPT_RESOLVE */
- /* release the returned reference; the cache itself will keep the
- * entry alive: */
- dns->inuse--;
- }
- }
- else {
- /* this is a duplicate, free it again */
- infof(data, "RESOLVE %s:%d is already cached, %s not stored!\n",
- hostname, port, addresses);
- Curl_freeaddrinfo(head);
+ /* put this new host in the cache */
+ dns = Curl_cache_addr(data, head, hostname, port);
+ if(dns) {
+ dns->timestamp = 0; /* mark as added by CURLOPT_RESOLVE */
+ /* release the returned reference; the cache itself will keep the
+ * entry alive: */
+ dns->inuse--;
}
if(data->share)