FpDebug: Fixed MemLeak on Windows: TProcessUtf8 was not freed / introduced in e104c4c418 - merge-request !41

This commit is contained in:
Martin 2021-11-20 13:01:36 +01:00
parent 7c0fdd1281
commit 9213ca32e8

View File

@ -660,23 +660,22 @@ function TDbgWinProcess.StartInstance(AParams, AnEnvironment: TStrings;
AWorkingDirectory, AConsoleTty: string; AFlags: TStartInstanceFlags; out AWorkingDirectory, AConsoleTty: string; AFlags: TStartInstanceFlags; out
AnError: TFpError): boolean; AnError: TFpError): boolean;
var var
AProcess: TProcessUTF8;
LastErr: Integer; LastErr: Integer;
begin begin
result := false; result := false;
AProcess := TProcessUTF8.Create(nil); FProcProcess := TProcessUTF8.Create(nil);
try try
// To debug sub-processes, this needs to be poDebugProcess // To debug sub-processes, this needs to be poDebugProcess
AProcess.Options:=[poDebugProcess, poDebugOnlyThisProcess, poNewProcessGroup]; FProcProcess.Options:=[poDebugProcess, poDebugOnlyThisProcess, poNewProcessGroup];
if siForceNewConsole in AFlags then if siForceNewConsole in AFlags then
AProcess.Options:=AProcess.Options+[poNewConsole]; FProcProcess.Options:=FProcProcess.Options+[poNewConsole];
AProcess.Executable:=Name; FProcProcess.Executable:=Name;
AProcess.Parameters:=AParams; FProcProcess.Parameters:=AParams;
AProcess.Environment:=AnEnvironment; FProcProcess.Environment:=AnEnvironment;
AProcess.CurrentDirectory:=AWorkingDirectory; FProcProcess.CurrentDirectory:=AWorkingDirectory;
AProcess.Execute; FProcProcess.Execute;
Init(AProcess.ProcessID, 0); Init(FProcProcess.ProcessID, 0);
Result:=true; Result:=true;
except except
on E: Exception do on E: Exception do
@ -691,7 +690,7 @@ begin
else else
{$endif i386} {$endif i386}
AnError := CreateError(fpErrCreateProcess, [Name, LastErr, E.Message, '']); AnError := CreateError(fpErrCreateProcess, [Name, LastErr, E.Message, '']);
AProcess.Free; FreeAndNil(FProcProcess);
end; end;
end; end;
end; end;