curl-library
Re: [patch] libcurl 7.12.2-20040917 and CURLOPT_VERBOSE may read free()ed data
Date: Fri, 01 Oct 2004 17:04:53 +0200
Daniel Stenberg wrote:
> On Wed, 29 Sep 2004, Bertrand Demiddelaer wrote:
>
>> Btw, my first attempt to put the code concerning dns cache update in
>> Curl_done() to Curl_disconnect() (basically copy-paste of the
>> 'Curl_resolv_unlock() .... Curl_hostcache_prune()' section) had lead
>> me to a infinite hang in test 001 (any ideas on it ?). That was
>> another of the bad reasons which made me study the current patch.
>
>
> Post the patch here and I'll have a go at it!
>
I didn't have time to go further recently... here is this "broken"
patch. It seems that clearing conn->dns_entry in Curl_disconnect() the
way I do it is a bit too late, or I missed something...
--- lib/hostip.c.00 Tue Sep 28 11:49:14 2004
+++ lib/hostip.c Tue Sep 28 11:49:24 2004
@@ -459,7 +459,11 @@
}
}
else {
+ if(data->share)
+ Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
dns->inuse++; /* we use it! */
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
rc = CURLRESOLV_RESOLVED;
}
--- lib/url.c.00 Fri Oct 1 16:47:43 2004
+++ lib/url.c Fri Oct 1 16:50:44 2004
@@ -1431,6 +1431,17 @@
data = conn->data;
+ if(conn->dns_entry)
+ Curl_resolv_unlock(data, conn->dns_entry); /* done with this */
+
+#if defined(CURLDEBUG) && defined(AGGRESIVE_TEST)
+ /* scan for DNS cache entries still marked as in use */
+ Curl_hash_apply(data->hostcache,
+ NULL, Curl_scan_cache_used);
+#endif
+
+ Curl_hostcache_prune(data); /* kill old DNS cache entries */
+
/*
* The range string is usually freed in curl_done(), but we might
* get here *instead* if we fail prematurely. Thus we need to be able
@@ -3229,7 +3240,8 @@
if(conn->bits.reuse) {
/* re-used connection, no resolving is necessary */
hostaddr = NULL;
- conn->dns_entry = NULL; /* we don't connect now so we don't have any fresh
+ /* we'll need to clear conn->dns_entry later in Curl_disconnect() */
+ /* conn->dns_entry = NULL; /* we don't connect now so we don't have any fresh
dns entry struct to point to */
if (conn->bits.httpproxy)
@@ -3479,17 +3491,6 @@
conn->newurl = NULL;
}
- if(conn->dns_entry)
- Curl_resolv_unlock(conn->data, conn->dns_entry); /* done with this */
-
-#if defined(CURLDEBUG) && defined(AGGRESIVE_TEST)
- /* scan for DNS cache entries still marked as in use */
- Curl_hash_apply(data->hostcache,
- NULL, Curl_scan_cache_used);
-#endif
-
- Curl_hostcache_prune(data); /* kill old DNS cache entries */
-
/* this calls the protocol-specific function pointer previously set */
if(conn->curl_done)
result = conn->curl_done(conn, status);
Received on 2004-10-01