pleriche/FastMM5

UnregisterExpectedMemoryLeak not working

Opened this issue · 0 comments

Hello,
Please note that after setting this memory manager, pointers unregistered from Leak list still reported:

uses
  FastMM5;
var
  OldMM   : TMemoryManagerEx;
  FileName : string;

function NewRegisterMemoryLeak(P:Pointer):Boolean;
begin
  Result := OldMM.RegisterExpectedMemoryLeak(P);
end;

function NewUnregisterMemoryLeak(P:Pointer):Boolean;
begin
  Result := OldMM.UnregisterExpectedMemoryLeak(P);
end;

const
  NewMM : TMemoryManagerEx =
  (
    GetMem                       : NewAllocMem;
    FreeMem                      : NewFreeMem;
    ReallocMem                   : NewReallocMem;
    AllocMem                     : NewAllocMem;
    RegisterExpectedMemoryLeak   : NewRegisterMemoryLeak;
    UnregisterExpectedMemoryLeak : NewUnregisterMemoryLeak;
  );

initialization
  GetMemoryManager(OldMM);
  FileName := ChangeFileExt(ParamStr(0),'.leak');
  DeleteFile(FileName);
  FastMM_SetEventLogFilename(PChar(FileName));
  FastMM_OutputDebugStringEvents := FastMM_LogToFileEvents;
  FastMM_MessageBoxEvents        := [];
  FastMM_EnterDebugMode;
  SetMemoryManager(NewMM);
finalization
end.

MemoryModule and HookList are reported as leak when application terminated:

procedure InstallModule;
var
  Bytes : TBytes;
begin
  if Assigned(MemoryModule) or IsDesigntime then Exit;
  HookList          := TKeyRecord<TMemoryModule>.Create;

  Bytes             := ExtractResource('MEMORYMODULE.DLL');
  MemoryModule      := MemoryLoadLibary(Bytes);
  LoadLibraryMemory := MemoryGetProcAddress(MemoryModule,'LoadLibraryMemory');
  FreeLibraryMemory := MemoryGetProcAddress(MemoryModule,'FreeLibraryMemory');

  OldLoadLibrary    := HookProcedure(@LoadLibrary,@LoadLibraryHooked,LoadLibraryHook);
  OldLoadLibraryEx  := HookProcedure(@LoadLibraryEx,@LoadLibraryExHooked,LoadLibraryExHook);
  OldGetProcAddress := HookProcedure(@GetProcAddress,@GetProcAddressHooked,GetProcAddressHook);
  OldFreeLibrary    := HookProcedure(@FreeLibrary,@FreeLibraryHooked,FreeLibraryHook);

  UnregisterExpectedMemoryLeak(MemoryModule);
  UnregisterExpectedMemoryLeak(HookList);
end;

Best regards.