EIdConnClosedGracefully memory leak

I have ReportMemoryLeaksOnShutDown enabled in my Delphi XE5 (Indy 10.6.0.5040) app and I'm getting this memory leak notification:

--------------
An unexpected memory leak has occurred. The unexpected small block leaks are:

41 - 56 bytes: EIdConnClosedGracefully x 1
73 - 88 bytes: UnicodeString x 1
--------------

I've narrowed it down to a background thread which makes a TIdHTTP.Post() call. Here is a simplified version of that thread which reproduces the leak when compiled in 64-bit mode:

procedure TValidateThread.Execute;
var
  Http: TIdHTTP;
  Params: TStringList;
begin
  FreeOnTerminate := True;
  Params := TStringList.Create;
  Params.Add('Command=Test');
  Http := TIdHTTP.Create;
  Http.Post('http://www.example.com/test.php', Params);
  Http.Free;
  Params.Free;
end;

If I comment out the Http.Post line, no leak is reported. Also, no leak if I change it from Post() to Get(). And no leak when compiled in 32-bit mode. The problem is only with Post() in 64-bit mode. Is this a Delphi or Indy bug?
0
Kent
6/2/2015 7:38:01 PM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

6 Replies
879 Views

Similar Articles

[PageSpeed] 57

Kent wrote:

> I've narrowed it down to a background thread which makes a TIdHTTP.Post()
> call. Here is a simplified version of that thread which reproduces the 
leak when
> compiled in 64-bit mode:

Is the exception escaping TIdHTTP.Post() into your Execute() code?  If so, 
then any uncaught exception that escapes from Execute() is caught by TThread 
and stored in the TThread.FatalException property, and then TThread frees 
the exception at the end of TThread's destructor.

If TIdHTTP.Post() does raise an exception into your code, you are leaking 
your TIdHTTP and TStringList objects.  Your leak report does not include 
these objects, which suggests to me that the exception is not actually escaping 
from TIdHTTP.Post() into your code to begin with.  Indy uses standard try/finally 
and try/except blocks, it does not manually acquire/free any exceptions, 
so any leak of an exception object inside of Indy would have to be a failure 
on Delph's part, not on Indy's.

On the other hand, when I test your code as-is, I do not get an EIdConnClosedGracefully 
exception, I get an EIdHTTPProtocolException exception with a "404 Not Found" 
message instead.  Which is what should be happening, since the URL you showed 
is not a real URL for posting.

What I am more concerned about is that your leak report is so small.  When 
I test your code as-is, I get an exception from TIdHTTP.Post() (to be expected 
because of the invalid URL) and my leak report is much larger, which makes 
sense as the TIdHTTP object is leaked and everything associated with it is 
this also leaked.  When I fix those leaks in the code by using try/finally 
blocks, the entire leak report disappears.

However, I am testing with XE2, I have not tested with XE5 yet.

> The problem is only with Post() in 64-bit mode. Is this a Delphi or Indy 
bug?

It would have to be a Delphi bug, since Indy is not doing anything special 
with its exception handling (or lack of).  One, I am concerned that you are 
seeing EIdConnClosedGracefully instead of EIdHttpProtocolException, and two, 
I am concerned that your leak report is not reporting everything that the 
code you showed should be leaking.

Did you try debugging the code to see whether the exception is actually escaping 
TIdHTTP into Execute(), and if so that the exception is actually being caught 
in the TThread.FatalException property and freed in the TThread destructor?

-- 
Remy Lebeau (TeamB)
0
Remy
6/2/2015 8:27:56 PM
Kent wrote:

> I've narrowed it down to a background thread which makes a TIdHTTP.Post()
> call. Here is a simplified version of that thread which reproduces the 
leak when
> compiled in 64-bit mode:

Is the exception escaping TIdHTTP.Post() into your Execute() code?  If so, 
then any uncaught exception that escapes from Execute() is caught by TThread 
and stored in the TThread.FatalException property, and then TThread frees 
the exception at the end of TThread's destructor.

If TIdHTTP.Post() does raise an exception into your code, you are leaking 
your TIdHTTP and TStringList objects.  Your leak report does not include 
these objects, which suggests to me that the exception is not actually escaping 
from TIdHTTP.Post() into your code to begin with.  Indy uses standard try/finally 
and try/except blocks, it does not manually acquire/free any exceptions, 
so any leak of an exception object inside of Indy would have to be a failure 
on Delph's part, not on Indy's.

On the other hand, when I test your code as-is, I do not get an EIdConnClosedGracefully 
exception, I get an EIdHTTPProtocolException exception with a "404 Not Found" 
message instead.  Which is what should be happening, since the URL you showed 
is not a real URL for posting.

What I am more concerned about is that your leak report is so small.  When 
I test your code as-is, I get an exception from TIdHTTP.Post() (to be expected 
because of the invalid URL) and my leak report is much larger, which makes 
sense as the TIdHTTP object is leaked and everything associated with it is 
this also leaked.  When I fix those leaks in the code by using try/finally 
blocks, the entire leak report disappears.

However, I am testing with XE2, I have not tested with XE5 yet.

> The problem is only with Post() in 64-bit mode. Is this a Delphi or Indy 
bug?

It would have to be a Delphi bug, since Indy is not doing anything special 
with its exception handling (or lack of).  One, I am concerned that you are 
seeing EIdConnClosedGracefully instead of EIdHttpProtocolException, and two, 
I am concerned that your leak report is not reporting everything that the 
code you showed should be leaking.

Did you try debugging the code to see whether the exception is actually escaping 
TIdHTTP into Execute(), and if so that the exception is actually being caught 
in the TThread.FatalException property and freed in the TThread destructor?

-- 
Remy Lebeau (TeamB)
0
Remy
6/2/2015 9:14:02 PM
> Is the exception escaping TIdHTTP.Post() into your Execute() code?

In my actual code, I have the post() call in a try..except block with error logging and I use a valid URL pointing to php file on my private server. I should have mentioned I substituted in the fake url just for privacy purposes. So you would need to include a valid url to replicate the leak. The leak occurs with no exception firing so that isn't the issue. But it doesn't occur for Get() and doesn't occur when compiled for 32-bit mode.
0
Kent
6/2/2015 9:24:20 PM
Kent wrote:

> In my actual code, I have the post() call in a try..except block with
> error logging and I use a valid URL pointing to php file on my private
> server.

Then you should have shown that, insted of sending me on a wild goose chase. 
 Please always show REAL code, even if it is just example code.

> So you would need to include a valid url to replicate the leak.

I am still curious to know why you are getting an EIdConnClosedGracefully 
exception on a POST request in the first place.  That would imply that the 
server is closing its end of the connection, so either the server is rejecting 
the POST without sending back an HTTP response and is just kicking you out. 
 Or it is sending an HTTP response that does not include a "Content-Length" 
or "Transfer-Encoding: chunked" header, so the response is terminated by 
closing the socket (but TIdHTTP should not be raising an EIdConnClosedGracefully 
exception in that condition), or the server is closing the socket before 
TIdHTTP has received the entire response.

If you run your app in the debugger, can you see the exception at all?  What 
does the call stack look like for it?

> The leak occurs with no exception firing so that isn't the issue.

Obviously, it IS firing an exception, otherwise you would not be seeing it 
leak at all.  But if it is not reaching your code then Indy has to be catching 
it internally.  Either way, it still implies that Delphi is not freeing it 
after it is handled by an exception handler.

-- 
Remy Lebeau (TeamB)
0
Remy
6/2/2015 10:13:54 PM
These forums are hosed. I see duplicate replies from Remy and the lag is taking forever. 

Anyway, I created a new 64-bit app that contains nothing but the thread I posted (with a valid URL) and a button to create it. And of course I no longer get the memory leak indication. The original code is in a 50,000 line game server with lots of other stuff going on, including an Indy HTTP server and TCP server. I obviously can't post all that here so I don't know how I could ever get anyone to replicate this.
0
Kent
6/2/2015 10:28:52 PM
Kent wrote:

> In my actual code, I have the post() call in a try..except block with
> error logging and I use a valid URL pointing to php file on my private
> server.

Then you should have shown that, insted of sending me on a wild goose chase. 
 Please always show REAL code, even if it is just example code.

> So you would need to include a valid url to replicate the leak.

I am still curious to know why you are getting an EIdConnClosedGracefully 
exception on a POST request in the first place.  That would imply that the 
server is closing its end of the connection, so either the server is rejecting 
the POST without sending back an HTTP response and is just kicking you out. 
 Or it is sending an HTTP response that does not include a "Content-Length" 
or "Transfer-Encoding: chunked" header, so the response is terminated by 
closing the socket (but TIdHTTP should not be raising an EIdConnClosedGracefully 
exception in that condition), or the server is closing the socket before 
TIdHTTP has received the entire response.

If you run your app in the debugger, can you see the exception at all?  What 
does the call stack look like for it?

> The leak occurs with no exception firing so that isn't the issue.

Obviously, it IS firing an exception, otherwise you would not be seeing it 
leak at all.  But if it is not reaching your code then Indy has to be catching 
it internally.  Either way, it still implies that Delphi is not freeing it 
after it is handled by an exception handler.

-- 
Remy Lebeau (TeamB)
0
Remy
6/2/2015 10:53:24 PM
Reply:

Similar Artilces:

Memory Leak, Leak, Leak, Leak.....
All, I have spent a lot of time watching the life being sucked out of my computer as I develop using PB during the day. I can document PB 7.0 8030 leaking memory every time I open and close the library, save an userobject, open a datawindow, etc. Some times the memory comes back when when I close PB, but mostly not. On one occasion I watched a nearly full restoration of available memory after closing Powerbuilder and then MSOutlook. How could MSOutlook release memory? Anyhows, I just had to vent. Is anyone else suffering the slow loss of memory? I don't see a lot of thr...

Delphi 2009 memory leak
I have a small app that uses dbExpress for MS SQL. I have the apps ReportMemoryLeaksOnShutdown set to true. Any time I use dbExpress to call a simple stored procedure (returns a single record with 2 fields) when I close the application memory leaks are reported. I am unable to determine if there is a known memory leak with the dbExpress driver. Can anyone help? This is driving me nuts. Here is the message text: --------------------------- Unexpected Memory Leak --------------------------- An unexpected memory leak has occurred. The unexpected small block leaks are: 21 - 28 b...

Delphi XE memory leak?
Hi, I was browsing the net in search of DelphiXE reviews and features, when I found out [this| http://delphibugs.blogspot.com/2010/09/xe-new-bug-1-wild-memory-eating.html ] Can anyone confirm? I have not finished downloading the trial ISO yet (2 hours remaining <g>), but I will try to reproduce it myself when it's done. Cheers, G I didn't believe it would happen, but it did the same thing in my VM. I only even did it to say "doesn't happen here" because I find single purpose blogs like that astonishingly annoying. In any case, he's right. What&...

Delphi VCL Memory Leak?
I am dealing with a slow memory leak that causes a massive program to fail after more than a week running. So I started a leak hunt by stripping down the app to the first self written unit and checking. Low and Behold, it leaked. So I started with just a bare bones App - frame only, and it Leaked. I have duplicated it on Delphi 6 and on Borland Developer Studio 2006. Start with a new VCL app. Add nothing, but compile and run. Now Ctrl-alt-Del and set up to watch the memory of your empty app with out overl apping the app screen. Now click on your app and watch the memory size grow with every c...

Where is the memory leak in this Delphi code? [Edit]
"Also, ask here if you don't know which group is best for your post" - moderator, please move this if you know of a better forum. Thanks! Can anyone help? I asked this on Stack Overflow and got it closed as "not a real question" (because "where is my memory leak" isn't a real question?). I have been searching for weeks and am desparate. I have thrown out 95+% of my code and still hit out of memory errors. Can soemone pelase help me? [Update: I may not have made it clear that the memory leak is in the server, not the client. Sorry] Here's ...

Delphi 2009 memory consumption (leak?)
Hi! I'm converting an old project of a couple of hundred files to Delphi 2009. In the process, I'm also changing the policy so, that instead of adding all my folders with code files to search path, I add the code files directly to the project and keep the search path empty (this among other things because at least in older Delphi's the length of the search path was limited and I started hitting the limit). At the same time I want to clean the project so, that I only add the files really needed, since my folde rs contain lots of legacy code files also that are no longer used. ...

Delphi 2010 - dbexpress
Hi I use the dbx driver for firebird named dbxfb.dll and in my application i do a select every seconds. the memory of the process increase every 30 minutes but when i use Fastmm to check the memory leaks : no memory leak. I have noticed that if i do not do the open and close primitive, no more memory leak !! Here is my source LQuery := TSQLQuery.Create(Self); LQuery.SQLConnection := SQLConnection; LQuery.CommandText := 'SELECT * FROM '+ TableName + ' where EventId = :EventId'; try LQuery.ParamByName('EventId').AsInteger := EventId; LQuery.Open; LResult...

Delphi XE TSQLStoredProcedure Memory Leak
I am running into a memory leak when I am using a TSQLStoredProcedure created at run time with parameters. Here is code example that is creating the problem. {code} // Create the stored procedure. SQLStoredProcedureRecordEvent := TSQLStoredProc.Create(nil); // Set the parameters of the stored procedure. with SQLStoredProcedureRecordEvent do begin // Set the sql connection. SQLConnection := SendgridEventHandlerDM.DataModule_SendgridEventHandler. SQLConnection1; // Set the name of the procedure. StoredProcName := 'CreateBounceRecord'; ...

FastMM in Delphi 2010
Is there a way to get a memory leak report with FastMM either with the embeded version or the standalone that gives you the line number where the memory leak occur like Memcheck does. Thanks in advance. Ronaldo Santana wrote: > Is there a way to get a memory leak report with FastMM either with > the embeded version or the standalone that gives you the line number > where the memory leak occur like Memcheck does. > > Thanks in advance. I use this as default in my applications: ReportMemoryLeaksOnShutdown:= DebugHook <> 0; Cesar Romero Hi Cesar...

Delphi 2009 HTTPRIO Memory Leak
After wrestling with issues about when to and when not to free HTTPRIO objects created in code, I still have one problem: With Delphi 2009 I have a routine that calls a SOAP function derived from a WDSL call that returns a TXMLData objects (actually it is just some XML, but that is what was created by the interface). The HTTPRIO object is created in code. I am explictly freeing the returned TXMLData, but there remains some memory leaks which I am having problems tracking down. Are there any known gotchas for using this or are there other references I have to explicitly free? ...

superreview requested: [Bug 306785] memory leaks in PQG_ParamGenSeedLen : [Attachment 194622] fix for memory leaks
Julien Pierre <julien.pierre.bugs@sun.com> has asked Robert Relyea <rrelyea@redhat.com> for superreview: Bug 306785: memory leaks in PQG_ParamGenSeedLen https://bugzilla.mozilla.org/show_bug.cgi?id=306785 Attachment 194622: fix for memory leaks https://bugzilla.mozilla.org/attachment.cgi?id=194622&action=edit ------- Additional Comments from Julien Pierre <julien.pierre.bugs@sun.com> I have tested this and verified the 2 leaks are gone. all.sh still passes. I'm not 100% sure that my change in getPQseed is correct . The code was previously freeing and re...

Memory Leak or memory reconfig?
Memory issues on NW6.5 SP4 2GB of memory GWIA,MTA box with GWAVA I only know of the seg.nlm util used in conjunction with memcalc.exe tool to calculate the proper -u amount. This server does not qualify for this tool though because it has -2gb. Any ideas on how I should calculate the -u amount or should I be looking at another issue? Console messages: ----------------------------------------- 9-05-2006 7:02:48 pm: SERVER-5.70-3707 [nmID=120004] Server logical address space is running low. Increase the available logical space by restarting the server wit...

Releasing memory / memory leaks
I was always under the impression that when developing in ASP.Net you don't need to worry about releasing memory i.e. in your pages/functions/subs you can create as many variables/objects as you want, use them and then 'walk away' and let asp clear up the mess - but after doing some browsing on the web there are a number of people who do not this this is the case. Can anyone give me a definative answer on this.  i.e. if i have something like this at the top of my proc :  dim mObj as new MyClass do i have to put mObj = nothing at the end. What about things like colle...

memory, memory, memory
Name: bruce Email: bruceatlmcsoftwaredotcom Product: Firefox Summary: memory, memory, memory Comments: Hi, I run firefox all day like I run Outlook. I open/close a zillion tabs using a single instance of firefox, usually no more than 6 tabs at a time. But I've had 20 tabs open at once while I'm culling the NY Times articles I want to print. Every so often my mouse stops moving. Taskmgr shows firefox has 256 Megs of memory (or something equally large) and is using 95% of the cpu. Why?? Make this nonsense stop! Forget the IE/Firefox/Chrome competition. T...

Web resources about - EIdConnClosedGracefully memory leak - embarcadero.delphi.winsock

Resources last updated: 12/30/2015 3:32:36 PM