cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Memory leak in libcurl

From: Huzaifa Al Nahas <halnahas_at_gmail.com>
Date: Mon, 22 Dec 2008 11:33:57 -0800

Dan,
I used _CrtDumpMemoryLeaks() to check for memory leak. I recently
wrote a program that uses libcurl with ssl. Then _CrtDumpMemoryLeaks()
reported a memory leak. So I narrowed down the program to find out
where this memory leak happens. I found out that just initializing an
easy handle and cleaning it will lead to a leak (ie:
_CrtDumpMemoryLeaks() reporting a leak). It appears that
curl_easy_cleanup function does not clean everything that
curl_easy_init function reserves in memory.
The simple program listed below clarifies this behavior. The program
initializes an easy handle and cleans it, and _CrtDumpMemoryLeaks()
reports a memory leak. You may run the program below and check it out.
It is worth noting that this seems to be related to ssl because when I
build curl without ssl support, _CrtDumpMemoryLeaks() reports no
memory leak for the same code. Is there any other cleanup functions
that need to be called when curl is built with ssl support?

#include <iostream>
#include <curl/curl.h>
#include <crtdbg.h>

#define _CRTDBG_MAP_ALLOC

int main(int argc, char *argv[])
{
 CURL *curl;

 curl_global_init(CURL_GLOBAL_ALL|CURL_GLOBAL_WIN32);

 curl = curl_easy_init();

 curl_easy_cleanup(curl);

 curl_global_cleanup();

 if (_CrtDumpMemoryLeaks())
         std::cout << "Memory Leak" << std::endl;
 else
         std::cout << "No memory leak found" << std::endl;

 return 0;
}

Thanks,
Huzaifa

On Mon, Dec 22, 2008 at 11:09 AM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Mon, 22 Dec 2008, Huzaifa Al Nahas wrote:
>
>> The memory leak is reported even if curl_global_cleanup() is called. This
>> is true whether I call curl_global_init directly or indirectly. The code
>> below reports a memory leak
>
> We track memory use in 500+ tests run daily on numerous operating systems.
> It doesn't leak in that "plain" use case now and it hasn't done so in a very
> long time AFAIK.
>
> Can you please be a bit more specific about where exactly this claimed
> memory leak occurs?
>
> --
>
> / daniel.haxx.se
>
Received on 2008-12-22