From 5d6489a45ada618b49959f177bdd0ffe2a537859 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 19 Jan 2024 15:43:26 +0100 Subject: [PATCH] FpDebug: Fix mem leak, if breakpoint is set to "auto destroy" --- components/fpdebug/fpdbgclasses.pp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/components/fpdebug/fpdbgclasses.pp b/components/fpdebug/fpdbgclasses.pp index f63f9deccc..62890f035a 100644 --- a/components/fpdebug/fpdbgclasses.pp +++ b/components/fpdebug/fpdbgclasses.pp @@ -478,6 +478,7 @@ type FEnabled: boolean; FOn_Thread_StateChange: TFpDbgBreakpointStateChangeEvent; protected + procedure SetFreeByDbgProcess(AValue: Boolean); virtual; procedure SetEnabled(AValue: boolean); function GetState: TFpDbgBreakpointState; virtual; public @@ -493,7 +494,8 @@ type procedure ResetBreak; virtual; abstract; // FreeByDbgProcess: The breakpoint will be freed by TDbgProcess.Destroy - property FreeByDbgProcess: Boolean read FFreeByDbgProcess write FFreeByDbgProcess; + // If the breakpoint does not have a process, it will be destroyed immediately + property FreeByDbgProcess: Boolean read FFreeByDbgProcess write SetFreeByDbgProcess; property Enabled: boolean read FEnabled write SetEnabled; property State: TFpDbgBreakpointState read GetState; // Event runs in dbg-thread @@ -506,6 +508,7 @@ type private FProcess: TDbgProcess; protected + procedure SetFreeByDbgProcess(AValue: Boolean); override; procedure UpdateForLibraryLoaded(ALib: TDbgLibrary); virtual; procedure UpdateForLibrareUnloaded(ALib: TDbgLibrary); virtual; property Process: TDbgProcess read FProcess; @@ -1014,6 +1017,11 @@ begin Result := bksUnknown; end; +procedure TFpDbgBreakpoint.SetFreeByDbgProcess(AValue: Boolean); +begin + FFreeByDbgProcess := AValue; +end; + procedure TFpDbgBreakpoint.SetEnabled(AValue: boolean); begin if AValue then @@ -3687,6 +3695,13 @@ end; { TFpInternalBreakBase } +procedure TFpInternalBreakBase.SetFreeByDbgProcess(AValue: Boolean); +begin + inherited SetFreeByDbgProcess(AValue); + if AValue and (FProcess = nil) then + Destroy; +end; + procedure TFpInternalBreakBase.UpdateForLibraryLoaded(ALib: TDbgLibrary); begin //