From b1851ef38dd4c9246084ab72866250b07139e3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Ha=CC=88user?= <8659494+mhaeuser@users.noreply.github.com> Date: Sat, 1 Apr 2023 18:08:53 +0200 Subject: [PATCH] BaseTools/ImageTool: Fix PeScan error handling --- BaseTools/ImageTool/ImageTool.c | 1 - BaseTools/ImageTool/PeScan.c | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/BaseTools/ImageTool/ImageTool.c b/BaseTools/ImageTool/ImageTool.c index 63e5312f62..9b018cc41e 100644 --- a/BaseTools/ImageTool/ImageTool.c +++ b/BaseTools/ImageTool/ImageTool.c @@ -107,7 +107,6 @@ PeXip ( Pe = NULL; if (!Result) { - ToolImageDestruct (&Image); return RETURN_ABORTED; } diff --git a/BaseTools/ImageTool/PeScan.c b/BaseTools/ImageTool/PeScan.c index 8c286f4f4b..847eaff448 100644 --- a/BaseTools/ImageTool/PeScan.c +++ b/BaseTools/ImageTool/PeScan.c @@ -450,6 +450,7 @@ ToolContextConstructPe ( Result = ScanPeGetHeaderInfo (&Image->HeaderInfo, &Context, ModuleType); if (!Result) { fprintf (stderr, "ImageTool: Could not retrieve header info\n"); + ToolImageDestruct (Image); FreeAlignedPages (Destination, DestinationPages); return false; } @@ -457,6 +458,7 @@ ToolContextConstructPe ( Result = ScanPeGetDebugInfo (&Image->DebugInfo, &Context); if (!Result) { fprintf (stderr, "ImageTool: Could not retrieve debug info\n"); + ToolImageDestruct (Image); FreeAlignedPages (Destination, DestinationPages); return false; } @@ -464,6 +466,7 @@ ToolContextConstructPe ( Result = ScanPeGetSegmentInfo (&Image->SegmentInfo, &Image->HiiInfo, &Context); if (!Result) { fprintf (stderr, "ImageTool: Could not retrieve segment info\n"); + ToolImageDestruct (Image); FreeAlignedPages (Destination, DestinationPages); return false; } @@ -471,6 +474,7 @@ ToolContextConstructPe ( Result = ScanPeGetRelocInfo (&Image->RelocInfo, &Context); if (!Result) { fprintf (stderr, "ImageTool: Could not retrieve reloc info\n"); + ToolImageDestruct (Image); } FreeAlignedPages (Destination, DestinationPages);