Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-03

AddTerminateProc leak?

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hello,

The test:

=== begin code ===

program project1;

uses
heaptrc,

  SysUtils;
  function _Finalize: boolean;
  begin
    WriteLn('END');
    Result := True;
  end;
begin
  WriteLn('START');
  AddTerminateProc(@_Finalize);
  WriteLn('END 1');
  Sleep(1000);
  DeleteFile('HT.TXT');
  SetHeapTraceOutput('HT.TXT');
end.

=== end code ===

The result:

=== begin trace ===
Heap dump by heaptrc unit
50 memory blocks allocated : 1226/1344
49 memory blocks freed : 1218/1336
1 unfreed memory blocks : 8
True heap size : 196608 (112 used in System startup) True free heap : 196416
Should be : 196424
Call trace for block $0018F150 size 8
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
=== end trace ===

The leak is returned even calling the CallTerminateProcs function.

I did something wrong or is it really a leak?

Thank you!

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

silvioprog
to silvioprog
silvioprog wrote 56 lines
Hello, The test: === begin code === program project1; uses heaptrc, SysUtils; function _Finalize: boolean; begin WriteLn('END'); Result := True; end; begin WriteLn('START'); AddTerminateProc(@_Finalize); WriteLn('END 1'); Sleep(1000); DeleteFile('HT.TXT'); SetHeapTraceOutput('HT.TXT'); end. === end code === The result: === begin trace === Heap dump by heaptrc unit 50 memory blocks allocated : 1226/1344 49 memory blocks freed : 1218/1336 1 unfreed memory blocks : 8 True heap size : 196608 (112 used in System startup) True free heap : 196416 Should be : 196424 Call trace for block $0018F150 size 8 $BAADF00D $BAADF00D $BAADF00D $BAADF00D $BAADF00D $BAADF00D $BAADF00D $BAADF00D === end trace === The leak is returned even calling the CallTerminateProcs function. I did something wrong or is it really a leak? Thank you!

Delphi 7+ has the SysUtils.FreeTerminateProcs procedure that frees the method added via the SysUtils.AddTerminateProc procedure.

I'll make a patch implementing it ...

Thank you!

Silvio Clécio My public projects - github.com/silvioprog

Reply by email