Why memory leak for Indy 10?

I have this leak in Indy 10.5.7 (under Delphi 7).

5 - 12 bytes: TIdThreadSafeInteger x 1
21 - 36 bytes: TIdCriticalSection x 2


I am using Indy as follows:

function getWeb(a,b:Integer):Integer;
var url: string;
    H: TIdHttp;
    SS: TStringStream;
begin
  url := 'http://blabla';
  H := TIdHttp.Create(nil);
  try
    SS := TStringStream.Create('');
    try
      H.Get(url, SS);
      Result := StrToInt(SS.DataString);
    FINALLY
     SS.Free;
    END;
  finally H.Free;
  end;

The leak itself does not bother me, because it disconnects when the application is turned off. This causes my melon to explode - this is an error message that I see every time I close the application.

Why does this leak appear?


I checked the Indy website, but that hardly makes sense. In any case, it seems that this error cannot be fixed: the latest version of Indy cannot be compiled with Delphi 7. The only solution could be Indy 9. Update: it looks like v10.203 on the website is actually called v10.2.3 .

+3
source share
3

, FastMM, , . , Delphi 2010, :

  • IdGlobal.pas
  • "C:\Program Files\Embarcadero\RAD Studio\7.0\source\Indy\Indy10\System" ( ).

:

{$IFNDEF DOTNET}
  {$IFDEF REGISTER_EXPECTED_MEMORY_LEAK}
function IndyRegisterExpectedMemoryLeak(AAddress: Pointer): Boolean;
{$IFDEF USEINLINE}inline;{$ENDIF}
begin

  // ===== My modification begins =====================

    Result := FastMM4.RegisterExpectedMemoryLeak(AAddress);
    Exit;


  // ===== My modification ends =====================

, .

+4

IdStack, .

IdStack.pas

:

{$ IFNDEF DOTNET}  
   {$ IFDEF} REGISTER_EXPECTED_MEMORY_LEAK
      IndyRegisterExpectedMemoryLeak (GStackCriticalSection); 
   {$ ENDIF} 
{$ ENDIF} 

finalization 

    // Dont Free. If shutdown is from another Init section, it can cause GPF When stack 
    // Tries to access it. App will kill it off anyways, so just let it leak 

    // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    // THIS LINE AND INCLUDE A COMMENT LINE DOWN 
    if GStackCriticalSection <> nil then FreeAndNil (GStackCriticalSection);
    // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

    {$ IFDEF} FREE_ON_FINAL 
    // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    // FreeAndNil (GStackCriticalSection); // DISABLE THIS LINE
    // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    {$ ENDIF} 

    end. 

10.515 Indy, http://indy.fulgan.com/ZIP/

+1

DPR

Application.terminate; 
if GThreadCount <> Nil then GThreadCount.Free; 

Add using IdThread.

More!

0
source

All Articles