Knowledgebase: Leaks
6.x: How to register expected mem-leak?
Posted by Alexander Alexeev on 31 October 2011 11:27
EurekaLog 6 doesn't have any pre-defined RegisterExpectedLeak-like function, but you can do this by using such code:

uses
ELeaks;
var
EurekaLogAddLeak: procedure(const LeakType: AnsiString; LeakSize, LeakCount: DWord; LeakCallStack: TRawCallStack);
procedure My_Internal_AddLeak(const LeakType: AnsiString; LeakSize, LeakCount: DWord; LeakCallStack: TRawCallStack);
begin
if { this is unwanted leak } then
Exit;
EurekaLogAddLeak(LeakType, LeakSize, LeakCount, LeakCallStack);
end;
initialization
EurekaLogAddLeak := AddLeak;
AddLeak := My_Internal_AddLeak;
end.

 

In order to identify leak - you can analyze passed arguments (for leak type, leak size and leak call stack).

Call stack is array of RAW addresses of fixed size. Start with 0 and loop though High(LeakCallStack), stop once encounter 0 address.

You can also get a textual description of each address by using GetSourceInfoByAddr function:

var
DebugInfo: TEurekaDebugInfo;
begin
// walk through call stack or just pick first item - your choice
for n := 0 to High(LeakCallStack) - 1 do
begin
if LeakCallStack[n] = 0 then
Break;
if GetSourceInfoByAddr(LeakCallStack[n], @DebugInfo) then
// DebugInfo contains description of LeakCallStack[n]
else
// Only RAW address is available
end;
end;

Help Desk Software by Kayako Resolve