FpDebug: fix mem leak. Libraries were not freed on Unload.

This commit is contained in:
Martin 2021-12-06 00:39:46 +01:00
parent 1b1dd8f5fa
commit 07e3817870
3 changed files with 14 additions and 2 deletions

View File

@ -671,6 +671,7 @@ type
function GetConsoleOutput: string; virtual;
procedure SendConsoleInput(AString: string); virtual;
procedure ClearAddedAndRemovedLibraries;
function AddThread(AThreadIdentifier: THandle): TDbgThread;
function GetThreadArray: TFPDThreadArray;
procedure ThreadsBeforeContinue;
@ -967,7 +968,11 @@ begin
end;
procedure TLibraryMap.ClearAddedAndRemovedLibraries;
var
lib: TDbgLibrary;
begin
for lib in FLibrariesRemoved do
lib.Free;
FLibrariesAdded := [];
FLibrariesRemoved := [];
end;
@ -1839,6 +1844,7 @@ begin
//FreeItemsInMap(FBreakMap);
FreeItemsInMap(FThreadMap);
FreeItemsInMap(FLibMap);
FLibMap.ClearAddedAndRemovedLibraries;
FreeAndNil(FWatchPointData);
FreeAndNil(FBreakMap);
@ -2091,6 +2097,12 @@ begin
// Do nothing
end;
procedure TDbgProcess.ClearAddedAndRemovedLibraries;
begin
{$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadIdNotMain('TBreakLocationMap.AddLocotion');{$ENDIF}
FLibMap.ClearAddedAndRemovedLibraries;
end;
function TDbgProcess.AddThread(AThreadIdentifier: THandle): TDbgThread;
var
IsMainThread: boolean;

View File

@ -1591,6 +1591,8 @@ begin
end;
FreeAndNil(FCommandToBeFreed);
FCurrentProcess.ClearAddedAndRemovedLibraries;
if FCommand <> nil then
FCommand.DoBeforeLoopStart;

View File

@ -1391,7 +1391,6 @@ var
begin
Result := TDbgWinLibrary.Create(Self, HexValue(AInfo.lpBaseOfDll, SizeOf(Pointer), [hvfIncludeHexchar]), AInfo.hFile, TDbgPtr(AInfo.lpBaseOfDll), AInfo);
ID := TDbgPtr(AInfo.lpBaseOfDll);
FLibMap.ClearAddedAndRemovedLibraries;
FLibMap.Add(ID, Result);
if (Result.DbgInfo.HasInfo) or (Result.SymbolTableInfo.HasInfo)
then FSymInstances.Add(Result);
@ -1406,7 +1405,6 @@ begin
ID := TDbgPtr(AInfo.lpBaseOfDll);
if not FLibMap.GetData(ID, Lib) then Exit;
FSymInstances.Remove(Lib);
FLibMap.ClearAddedAndRemovedLibraries;
FLibMap.Delete(ID);
end;