cURL
Haxx ad
libcurl

Shopping cart software, Online file storage, Online photo storage, Hosted shopping cart, Contact management software, Email marketing software, Project management software, Issue tracking software, Online notepad, Web publishing software

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-library Archives

RE: What is the proper way to get libcurl to free it resources when used within a C++ Class?

From: Dantzler, DeWayne C <dewayne.c.dantzler_at_boeing.com>
Date: Fri, 27 Nov 2009 04:58:47 -0800

On Tuesday 24 of November 2009 01:50:02 Dantzler, DeWayne C wrote:
> I'm using libcurl with C++ classes in a single threaded application by
> setting up the curl env in the constructor and invoking cleanup
> operation in the destructor, but I'm having trouble freeing the
> allocated memory. I read the curl documentation and tutorial. What is
> the correct method of freeing resources?

Kamil wrote:

It doesn't matter what programming paradigma are you actually using. Just call
curl_global_init()/curl_easy_cleanup() once per whole program. A singleton might be a good candidate if you like clean object-oriented design?

Then for each curl_easy_init() you should call one curl_easy_cleanup(). You can wrap it to class and call the functions in its ctor/dtor. Or perhaps use cURLpp binding which does the job for you?

Looking at your example again, one thing is clear. You can't call
curl_global_cleanup() before curl_easy_cleanup().

=============================================================
Thanks

I took your suggestions to try a Singleton and it worked!! Placing the calls to curl_global_init() and curl_easy_init() in the ctor of the Singleton and curl_easy_cleanup()/curl_global_cleanup() in the dtor did not result in a crash or memory leaks.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-11-27

These mail archives are generated by hypermail.

donate! Page updated November 16, 2009.
web site info

File upload with ASP.NET