From d9daa6776bdd38ca4b14fb874219b62df297af5f Mon Sep 17 00:00:00 2001 From: juha Date: Fri, 6 Mar 2020 20:09:47 +0000 Subject: [PATCH] FpDebug: Prevent an access violation in TDbgImageLoader constructor. Issue #36763. git-svn-id: trunk@62700 - --- components/fpdebug/fpdbgloader.pp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/components/fpdebug/fpdbgloader.pp b/components/fpdebug/fpdbgloader.pp index cce66ec4ca..a0ffc7d987 100644 --- a/components/fpdebug/fpdbgloader.pp +++ b/components/fpdebug/fpdbgloader.pp @@ -74,12 +74,12 @@ type constructor Create; virtual; constructor Create(AFileName: String; ADebugMap: TObject = nil; ALoadedTargetImageAddr: TDBGPtr = 0); - procedure ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); virtual; {$ifdef USE_WIN_FILE_MAPPING} constructor Create(AFileHandle: THandle; ADebugMap: TObject = nil; ALoadedTargetImageAddr: TDBGPtr = 0); {$endif} destructor Destroy; override; + procedure ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); virtual; procedure CloseFileLoader; procedure AddToLoaderList(ALoaderList: TDbgImageLoaderList); function IsValid: Boolean; @@ -224,14 +224,10 @@ begin FFileName := AFileName; FFileLoader := TDbgFileLoader.Create(AFileName); FImgReader := GetImageReader(FFileLoader, ADebugMap, False); - if FImgReader = nil then FreeAndNil(FFileLoader); - FImgReader.LoadedTargetImageAddr := ALoadedTargetImageAddr; -end; - -procedure TDbgImageLoader.ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); -begin - if IsValid then - FImgReader.ParseSymbolTable(AFpSymbolInfo); + if Assigned(FImgReader) then + FImgReader.LoadedTargetImageAddr := ALoadedTargetImageAddr + else + FreeAndNil(FFileLoader); end; {$ifdef USE_WIN_FILE_MAPPING} @@ -240,8 +236,10 @@ constructor TDbgImageLoader.Create(AFileHandle: THandle; ADebugMap: TObject; begin FFileLoader := TDbgFileLoader.Create(AFileHandle); FImgReader := GetImageReader(FFileLoader, ADebugMap, False); - if FImgReader = nil then FreeAndNil(FFileLoader); - FImgReader.LoadedTargetImageAddr := ALoadedTargetImageAddr; + if Assigned(FImgReader) then + FImgReader.LoadedTargetImageAddr := ALoadedTargetImageAddr + else + FreeAndNil(FFileLoader); end; {$endif} @@ -252,6 +250,12 @@ begin inherited Destroy; end; +procedure TDbgImageLoader.ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); +begin + if IsValid then + FImgReader.ParseSymbolTable(AFpSymbolInfo); +end; + procedure TDbgImageLoader.CloseFileLoader; begin if FFileLoader <> nil then