diff options
author | Daniel Stenberg <daniel@haxx.se> | 2011-12-31 10:28:10 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2011-12-31 10:45:27 +0100 |
commit | 5e0a44e4d58855a52b6e0744df4fab09ded3873c (patch) | |
tree | 92712f9fcec6f6ad95e4f139c35adedd25c1ae98 /lib/transfer.c | |
parent | 9e3f8c48501920c2c944f7a6eb447849500a3033 (diff) | |
download | curl-5e0a44e4d58855a52b6e0744df4fab09ded3873c.tar.gz |
CURLOPT_RESOLVE: avoid adding already present host names
The load host names to DNS cache function was moved to hostip.c and it
now makes sure to not add host names that already are present in the
cache. It would previously lead to memory leaks when for example using
the --resolve and multiple URLs on the command line.
Diffstat (limited to 'lib/transfer.c')
-rw-r--r-- | lib/transfer.c | 48 |
1 files changed, 1 insertions, 47 deletions
diff --git a/lib/transfer.c b/lib/transfer.c index 21bf2464c..9f05cfbd7 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -1405,52 +1405,6 @@ Transfer(struct connectdata *conn) return CURLE_OK; } -static CURLcode loadhostpairs(struct SessionHandle *data) -{ - struct curl_slist *hostp; - char hostname[256]; - char address[256]; - int port; - - for(hostp = data->change.resolve; hostp; hostp = hostp->next ) { - if(!hostp->data) - continue; - if(hostp->data[0] == '-') { - /* TODO: mark an entry for removal */ - } - else if(3 == sscanf(hostp->data, "%255[^:]:%d:%255s", hostname, &port, - address)) { - struct Curl_dns_entry *dns; - Curl_addrinfo *addr; - - addr = Curl_str2addr(address, port); - if(!addr) { - infof(data, "Resolve %s found illegal!\n", hostp->data); - continue; - } - - if(data->share) - Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE); - - /* put this host in the cache */ - dns = Curl_cache_addr(data, addr, hostname, port); - - if(data->share) - Curl_share_unlock(data, CURL_LOCK_DATA_DNS); - - if(!dns) { - Curl_freeaddrinfo(addr); - return CURLE_OUT_OF_MEMORY; - } - infof(data, "Added %s:%d:%s to DNS cache\n", - hostname, port, address); - } - } - data->change.resolve = NULL; /* dealt with now */ - - return CURLE_OK; -} - /* * Curl_pretransfer() is called immediately before a transfer starts. @@ -1490,7 +1444,7 @@ CURLcode Curl_pretransfer(struct SessionHandle *data) /* If there is a list of host pairs to deal with */ if(data->change.resolve) - res = loadhostpairs(data); + res = Curl_loadhostpairs(data); if(!res) { /* Allow data->set.use_port to set which port to use. This needs to be |