cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Possible memory leak in libcurl?

From: Gautam Mani <Gautam.Mani_at_Mobileum.com>
Date: Wed, 12 Jun 2002 08:50:06 -0700

Hi,

Okay, in my program I create one curl handle and periodically download files
through it via FTP. This handle is not cleaned up ever until the system
comes down (which is not expected to happen in a very long time). So
although I could not find a leak after I brought the system down, the memory
usage of the system still keeps going up.

I have attached a small section of the mallocdebug trace (taken on Win32).
Please notice that the allocations of 9K which happen in hostip.c:444 are
not released till the cleanup method is called. I tried to look into the
code; but since my understanding of the internals is still very basic; I am
finding it difficult to find a solution.

The line "listing %d" indicates the beginning of a new iteration (file
listing).

Is this name lookup allocation required everytime... or can it be avoided?
Why is the buffer not freed till cleanup is called? Are there some options
that I am missing -- I checked the manpage, but could not find anything.
Any pointers will be helpful.

Cheers,
Gautam

-----Original Message-----
From: Daniel Stenberg
To: Gautam Mani
Cc: libcurl Mailing list
Sent: 6/12/2002 4:18 AM
Subject: Re: Possible memory leak in libcurl?

On Wed, 12 Jun 2002, Gautam Mani wrote:

> I am using libcurl 7.9.6 on solaris 8. I have attached some sample
code
> which simulates the memory leak. I have verified the growing heap size
with
> tools like pmap. Basically just change the url to correct values and
point
> it to an empty directory. This is sufficient to reproduce the leak. Am
I
> doing something wrong here? I would really appreciate it if anyone
could
> give me some pointers on this.

Here's what I want you do do in order to track this down. I'm trying to
be
generic here so that these instructions can be used in more cases than
just
now:

1. Rebuild libcurl with -DMALLOCDEBUG (usually, rerunning configure with
   --enable-debug fixes this). 'make clean' first, then 'make' so that
   all files actually are rebuilt properly.

2. Add a line in your application code:

    curl_memdebug("memdump");

   This will make the malloc debug system output a full trace of all
resource
   using functions to the given file name.

3. Run your program as usual. Watch the 'memdump' file grow.

4. Make your program exit and use the proper libcurl cleanup functions
etc.
   So that all non-leaks are returned/freed properly.

5. Use the tests/memanalyze.pl perl script to analyze the memdump file:

    tests/memanalyze.pl < memdump

   This now outputs a report on what resources that were allocated but
never
   freed etc. This report is very fine for posting to the list!

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/

_______________________________________________________________

Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/

  • application/octet-stream attachment: mem.txt
Received on 2002-06-12