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 16:57:15 -0800

The idea is perfectly reasonable if the memory was in fact allocated
before main. However, it appears that leaked memory is being allocated
when curl_easy_init or curl_global_init are called. This is evident
because capturing a memory snapshot at the beginning of main and
comparing it to a snapshot before exit still reveals a memory leak as
the next program illustrates:

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

#define _CRTDBG_MAP_ALLOC

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

  _CrtMemState start, end, diff;

   _CrtMemCheckpoint(&start);

  CURL *curl;

  curl_global_init(CURL_GLOBAL_ALL|CURL_GLOBAL_WIN32);

  curl = curl_easy_init();

  curl_easy_cleanup(curl);

  curl_global_cleanup();

   _CrtMemCheckpoint( &end );

  if ( _CrtMemDifference(
                 &diff,
                 &start,
                 &end ) )
  {
     _CrtMemDumpStatistics( &diff );
     if (_CrtDumpMemoryLeaks( ))
             std::cout << "Memory leak" << std::endl;
  }
  else
  {
          std::cout << "No memory leak" << std::endl;
  }

        

  return 0;
}

On Mon, Dec 22, 2008 at 4:13 PM, Dan Fandrich <dan_at_coneharvesters.com> wrote:
> On Mon, Dec 22, 2008 at 02:26:18PM -0800, Huzaifa Al Nahas wrote:
>> Correction to a typo in the previous post (after -> before):
>>
>> Harmful is probably a strong word as you suggest. Problematic may be a
>> better word to describe it. Beyond the ability of reusing this "lost"
>> memory before the application closes, the main issue is that test cases
>> for memory leak will fail (I regard success as no memory leak reported
>> by _CrtDumpMemoryLeaks()) because of this insignificant memory leak.
>> That is the main reason I am looking for a function that frees this memory.
>
> Since this memory appears to be allocated before main() is even called and
> since this is a perfectly valid type of initialization for DLLs, I would
> imagine there is a function alongside _CrtDumpMemoryLeaks() that "resets"
> the leak counter that you can call at the start of your main() (after
> OpenSSL's allocations). If so, that's probably the most elegant way to
> solve the problem.
>
>>>> Dan
> --
> http://www.MoveAnnouncer.com The web change of address service
> Let webmasters know that your web site has moved
>
Received on 2008-12-23