On Tuesday 24 of November 2009 19:53:04 Dantzler, DeWayne C wrote:
> That is exactly what I did. I placed the calls for curl_global_init() 
> and
> curl_easy_init() in this order in a constructor and place the calls 
> for
> curl_global_cleanup() and curl_easy_cleanup() in the destructor. In 
> fact, I tried several different combinations in the destructor for the 
> curl_global_cleanup()and curl_easy_cleanup() methods, but each 
> combination had memory resource issues(see below). Now, I do call a 
> 3rd party
> library(Xerces) that also uses the curl library.

On Tuesday 24 of November 2009 Kamil Dudka wrote:
>> You are doing something a bit different. It's not good idea to call
>>curl_global_init()/curl_global_cleanup() more than once for nothing. I know 
>>there is something like a reference 
>>counter, but do not use it unless you really need to. Basically it's not 
>>thread-safe and it can trigger a memory leak >>under certain circumstances.

>> If you want to get more help from us, you'll need to write something like a 
>> minimal example we can compile and run. 
>> Then it's easy for us to tell you what's actually wrong in your code.

==============================================================

I'm not calling curl_global_init()/curl_global_cleanup() more than once. I'm 
calling them only once. Xerces is a 3rd party library and I have no access to 
the source or know how they are using curl in the their library. This is a 
large C++ application and I'm using curl in only one class. In my ctor, I call 
curl_global_init() first then make a call to curl_easy_init(). According to the 
curl documentation, if you call curl_global_init(), you should call 
curl_global_cleanup(). Likewise it says if you call curl_easy_init(), then you 
should call curl_easy_cleanup(), but when I do this the application crashes 
with a SIGSEGV, Segmentation fault. 

The call stack shows:
Results:Program received signal SIGSEGV, Segmentation fault.
=================================================
#0  0x63912920 in Curl_cookie_loadfiles+0x9c () 
#1  0x63933c74 in flush_cookies+0x8c () 
#2  0x639341ac in Curl_close+0x2ac 
#3  0x639624e8 in curl_easy_cleanup+0x3c ()

If I only call curl_global_cleanup() in the dtor, the application does not 
crash, but it leaks memory as reported by PurifyPlus.
Results:Memory Leak.
=================================================
      Memory leaked: 37013 bytes (60.9%); potentially leaked: 0 bytes (0%)
         MLK: 34256 bytes leaked at 0x401c49d0
         This memory was allocated from:
               malloc         [rtlib.o]
               calloc         [rtlib.o]
               Curl_open      [libcurl.sl.5.1]
               curl_easy_init [libcurl.sl.5.1]
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to