🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4990

Re: Possible memory leak with TIdTCPClient?

#4990
From: Remy Lebeau (TeamB)
Date: Mon, 08 Nov 2004 23:30
67 lines
2978 bytes
"Drew" <aemsley@brightwell.org.uk> wrote in message
news:418ff4b9$1@newsgroups.borland.com...

> Over time, the mmory used by my application increases, increasing
> from about 9Mb at start-up to more than 100 Mb after a day or so.
> I am fairly certain that it is the Indy component that is causing the
problem

It would help if you could isolate where the supposed memory leak is
actually occuring.  Please try to find the actual line in your thread code
that is causing it.

>     if ((!GetConnected()) | (!CommOpen))

You have a typo in that line.  It should be using the "||" operator, not the
"|" operator.

>         bool IPConnected = true;  //Assume OK until we find otherwise

Rather than duplicating all of that connecting code, you could just call
Open().

>             tempBuff = new char[dataLength];
>
>             m_clientSocket->ReadBuffer(tempBuff, dataLength);
>             delete[] tempBuff;

You don't need to read the buffer.  Just clear it directly:

    m_clientSocket->InputBuffer->Clear();

>         m_clientSocket->OpenWriteBuffer();

You are not clearing the write buffer if an error occurs.

    try
    {
        m_clientSocket->WriteBuffer(buffer, ByteCount);
        m_clientSocket->CloseWriteBuffer();
    }
    catch(const Exception &)
    {
        m_clientSocket->CancelWriteBuffer(); // <-- add this
        Close();
        return eTCPwriteFailed;
    }


>                 tempBuff = new char[dataLength];
>
>                 m_clientSocket->ReadBuffer(tempBuff, dataLength);
>
>                 memcpy(&ReplyBuf[Index], tempBuff, dataLength);

Why are you using a temporary buffer?  You could just read into your target
buffer directly:

    m_clientSocket->ReadBuffer(&ReplyBuf[Index], dataLength);

>                 if (Index == ReplySize)

Where is ReplySize being set to?  Why are you not simply passing ReplySize
to ReadBuffer() directly and read the entire reply in a single operation?


Gambit
Technical Details
Message-ID: <4190014c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!border2.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <418ff4b9$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,357e5d574910e956
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <418ff4b9$1@newsgroups.borland.com>
Subject: Re: Possible memory leak with TIdTCPClient?
Date: Mon, 8 Nov 2004 15:30:43 -0800
Lines: 69
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <4190014c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1099956556 68.69.17.41 (8 Nov 2004 15:29:16 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!border2.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail