Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect memory leaks with FastMM and the exitcode

I have an idea to enable FastMMs memleakreporting in the nightly automatic build. The messagebox should of course be disabled. The simplest would probably be if the applications exitcode was > 0 if there was a memleak. I did a quick test and the exitcode was 0 with a memleak and FastMM.

So my question is how can I detect if there was a memleak in FastMM to set the exitcode ?

like image 336
Roland Bengtsson Avatar asked Dec 03 '25 03:12

Roland Bengtsson


2 Answers

For my previous Delphi project I used MemCheck. It created text log file with all leaks it detected. I like this way of reporting and I see that FastMM has option do create such file: in FastMM4Options.inc there is LogErrorsToFile. This way you need to check log file and not check exitcode.

like image 71
Michał Niklas Avatar answered Dec 04 '25 17:12

Michał Niklas


I modified "procedure CheckBlocksOnShutdown(ACheckForLeakedBlocks: Boolean);" for my current customer to set the exitcode, so I could easily check in DUnit if a spawned process had a mem leak. I added a line at the end of the procedure:

  ...
  {$ifdef UseOutputDebugString}
  OutputDebugStringA(LLeakMessage);
  {$endif}
  ExitCode := 1;     <-- added this one
  if Assigned(OnMessage) then
    OnMessage(LLeakMessage);
  ...
like image 29
André Avatar answered Dec 04 '25 16:12

André



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!