cURL / Mailing Lists / curl-users / Single Mail

curl-users

Memory leak with curl 7.15.3

From: Sudipto Podder \(GR/EIL\) <sudipto.podder_at_ericsson.com>
Date: Mon, 21 May 2007 13:59:47 +0530

Hi,
I am using curl for the first time and have a small program (see below)
which is posting some requests. When I run this program,I see that the
memory size keeps growing on and on,but am unable to figure out what is
causing this ? Is there something wrong that I am doing or is there any
bug with this version of curl.

Your help will be highly appreciated.

Regards,
Sudipto Podder

  CURL *theCurl = curl_easy_init();
    curl_easy_setopt(theCurl, CURLOPT_URL, myHostName.data());
    curl_easy_setopt(theCurl, CURLOPT_PORT, myPort);
    curl_easy_setopt(theCurl, CURLOPT_POST, 1);
    curl_easy_setopt(theCurl, CURLOPT_WRITEFUNCTION,
EventClient::write_data);

    curl_easy_setopt(theCurl, CURLOPT_HEADER, 0);
    curl_easy_setopt(theCurl, CURLOPT_NOPROGRESS, 1);
    curl_easy_setopt(theCurl, CURLOPT_NOSIGNAL, 1);
    char theCookieFile[100];
    snprintf(theCookieFile, 100, "/tmp/cookie%d", (int) getpid());

    curl_easy_setopt(theCurl, CURLOPT_COOKIEJAR,theCookieFile);
    
    while( ! myInterrupt )
    {
        enqueue( myGetCommandDU );

        sleep(myInterval);
        MUTEX(myMutex);

        while( ! myInterrupt && ! myOutqueue->isEmpty() )
        {
            DataUnit *theMessage = myOutqueue->removeFirst();
            int theSize = 0;
            DataUnit *theUnit = 0;
            strstream theSendBuffer;
            strstream theWriteBuffer;

            try
            {

                curl_easy_setopt(theCurl, CURLOPT_WRITEDATA,
&theWriteBuffer);

                if( ! (*theMessage)(".sender").isDefined() )
                {
                    (*theMessage)(".sender") = getSender();
                }
                
                if( ! (*theMessage)(".messageId").isDefined() )
                {
                    (*theMessage)(".messageId") = -1;
                }
                
                theXmlEncoder.encode(*theMessage, theSendBuffer );
                theSendBuffer.write("\0", 1);
                char* theChars = theSendBuffer.str();
                theSendBuffer.rdbuf()->freeze(false);
                               

                curl_easy_setopt( theCurl, CURLOPT_POSTFIELDS,
theChars);
                curl_easy_setopt( theCurl, CURLOPT_POSTFIELDSIZE,
theSendBuffer.tellp() - 1 );

                //cerr << "Sending " << theSendBuffer.str() << endl;
                int theResult = curl_easy_perform(theCurl);
                PRINT << "Curl send result: " << theResult << endl;

                theWriteBuffer.put((unsigned char)0);

                if( theWriteBuffer.tellp()-1 > 0 )
                {
                    theUnit = new DataUnit("BGwInternal.UiMessage");
                    char* theWriteChars = theWriteBuffer.str();
                    theWriteBuffer.rdbuf()->freeze(false);

                    theXmlDecoder.parseBuffer(*theUnit,theWriteChars ,
theWriteBuffer.tellp()-1);

                    if( (*theUnit)(".arg.cmd.method") != "STFU" )
                    {
                        PRINT << "EventClient recived:\n" << (*theUnit)
<< endl;
                    }
                    
                    if( getSender().first('@') == RW_NPOS )
                    {
                        // When we start up our .sender is our instance
name.
                        // The first time we do a post there is no
sesion on the manager side,
                        // when the session is created the manager adds
'@' and our address to
                        // our .sender and uses it as .destination when
it sends it back in the reply.
                        // This to make sure we get an appropriate id.
                        setSender( (*theUnit)(".destination") );
                    }

                    myInqueue->append(theUnit);

                }
                else
                {
                    PRINT << "No response for \"" << theSendBuffer.str()
<< "\"" << endl;
                }

            }
            catch(StandardException& theExc)
            {
                try
                {

                    DataUnit *theReply = new DataUnit
("BGwInternal.UiMessage");

                    DataUnit reply = (*theReply)(".arg.cmdReply");

                    (*theReply)(".sender") =
(*theUnit)(".destination"); // Swap sender/dest in the reply
                    (*theReply)(".destination") = (*theUnit)(".sender");
                    (*theReply)(".messageId") =
(*theUnit)(".messageId");

                    reply(".status") = reply("commandError");
                    reply(".arg.error") = theExc.information();

                    (*theReply)(".arg") = reply;

                    PRINT << "Reply Command: \"" << endl << (*theReply)
<< "\"" << endl;

                    myOutqueue->append(theReply);

                }
                catch(StandardException& theOtherExc)
                {
                    PRINT << "Error printing errormessage: " <<
theOtherExc.information() << endl
                          << "The original error: " <<
theExc.information() << endl;
                }
            }

            

            delete theMessage;
        }
    }

 
Received on 2007-05-21