cURL / Mailing Lists / curl-library / Single Mail

curl-library

Possible memory leak with FTP and curl_easy_perform() ?

From: Jean-François Lavoie <lavoiejeff_at_videotron.ca>
Date: Fri, 10 Oct 2008 15:41:14 -0400

Hi,

    I am a new libcurl user and I think I may have found a memory leak
in repeated FTP transfers using the same curl handle. Maybe I am just
using the library in a way it is not intented for.

Here is my platform information :

platform : MS windows XP SP2
libcurl version : 7.18.00 win32 no SSL vc6 (downloaded from
http://curl.haxx.se/download/libcurl-7.18.0-win32-msvc.zip )
compiler : MS visual studio 2005

    The problem I found can be easily reproduced by taking the ftpget.c
example file (included in the docs/example folder ) and adding a while
(true) instruction to make the curl_easy_perform() call repeatedly.
Doing this, without changing any curl options between the
curl_easy_perform() calls makes the ftpget program take more and more
memory over time, which can be seen with the task manager in windows. I
tested it and it does not take more and more memory using the same
function call order in HTTP mode instead of FTP.

this will cause the leak :

program 1
{
    curl_global_init()
    curl_easy_init()
    curl_easy_setopt()...

    while (true)
    {
        curl_easy_perform()
    }

    curl_easy_cleanup()
    curl_global_cleanup()
}

    It seems the documentation recommends re-using the same handle so I
would guess it is perfectly normal to use the library this way for
multiple sequential FTP transfers.

    The following program does the same thing, but will not take more
and more memory over time. It calls curl_easy_init() and
curl_easy_cleanup() for each FTP transfer.

this will NOT cause the leak :

program 2
{
    curl_global_init()

    while(true)
    {
        curl_easy_init()
        curl_easy_setopt()...

        curl_easy_perform()

        curl_easy_cleanup()
    }

    curl_global_cleanup()
}

    Please let me know if it is a problem from the library or if I am
just using the library in a wrong way.

    Thank you very much, and many thanks for the great work, CURL is
wonderful !

Jeff
Received on 2008-10-10