cURL / Mailing Lists / curl-users / Single Mail

curl-users

SSL Context not cleaned up in multi handle

From: Lau, Hang Kin <hklau_at_avistar.com>
Date: Fri, 16 Feb 2007 17:27:56 -0800

The flow of my program is similar to this:
 
curl* pEasyHandle = curl_easy_init();
curl* pMultiHandle = curl_multi_init();
 
curl_easy_setopt(pEasyHandle, CURLOPT_CAINFO, "cacert.pem");
curl_easy_setopt(pEasyHandle, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(pEasyHandle, CURLOPT_SSL_VERIFYHOST, 2);
 
curl_multi_add_handle(pMultiHandle, pEasyHandle);
 
while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(pMultiHandle,
&integer);
 
curl_multi_remove_handle(pMultiHandle, pEasyHandle);
 
curl_easy_cleanup(pEasyHandle);
curl_multi_cleanup(pMultiHandle);
 
 
I am using MSVC .net and I found that when the process terminates, a
large amount of memory blocks were detecting as "memory leaks". I also
found that the content of "cacert.pem" were in those memory blocks.
Those may not be actual memory leaks but the large amount of blocks
detected by MSVC is disturbing as when the process ends, it takes MSVC a
while to display all the blocks.
 
It seems curl_multi_cleanup() didn't release the SSL ctx in it's
connection cache as curl_easy_cleanup() does.
 
By making the following changes, it seems to work and cleanup the SSL
ctx correctly but I am not sure if it could break something else?
 
Index: curl/lib/multi.c
===================================================================
--- curl/lib/multi.c (curl 7.16.0)
+++ curl/lib/multi.c (working copy)
@@ -591,7 +591,10 @@
       /* and modify the connectindex since this handle can't point to
the
          connection cache anymore */
       if(easy->easy_conn)
+ {
+ easy->easy_conn->data = NULL;
         easy->easy_conn->connectindex = -1;
+ }
     }
 
     /* change state without using multistate(), only to make
singlesocket() do
Index: curl/lib/url.c
===================================================================
--- curl/lib/url.c (curl 7.16.0)
+++ curl/lib/url.c (working copy)
@@ -1687,6 +1687,8 @@
   if (!conn)
     return;
 
+ Curl_ssl_close(conn);
+
   /* close possibly still open sockets */
   if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET])
     sclose(conn->sock[SECONDARYSOCKET]);
@@ -1796,8 +1798,6 @@
                                        allocated by libidn */
 #endif
 
- Curl_ssl_close(conn);
-
   /* Indicate to all handles on the pipe that we're dead */
   if (IsPipeliningEnabled(data)) {
     signalPipeClose(conn->send_pipe);
Received on 2007-02-17