From d9af5af8d96866821e50882fbd45686c28aaafed Mon Sep 17 00:00:00 2001 From: Star Zeng Date: Fri, 11 Aug 2017 11:02:39 +0800 Subject: MdeModulePkg DxeCore: Fix double free pages on LoadImage failure path https://bugzilla.tianocore.org/show_bug.cgi?id=667 reported there is double free pages on LoadImage failure path. CoreLoadPeImage() ... return EFI_SUCCESS; Done: // // Free memory. // if (DstBufAlocated) { CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages); } ... CoreUnloadAndCloseImage() ... if ((Image->ImageBasePage != 0) && FreePage) { CoreFreePages (Image->ImageBasePage, Image->NumberOfPages); } ... This patch is to follow the suggestion at https://lists.01.org/pipermail/edk2-devel/2017-August/013112.html to set Image->ImageContext.ImageAddress and Image->ImageBasePage to 0 after the free in CoreLoadPeImage(). Cc: Liming Gao Cc: Andrew Fish Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdeModulePkg/Core/Dxe/Image/Image.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'MdeModulePkg/Core') diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 03e979a604..4e22aa6dc7 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -788,6 +788,8 @@ Done: if (DstBufAlocated) { CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages); + Image->ImageContext.ImageAddress = 0; + Image->ImageBasePage = 0; } if (Image->ImageContext.FixupData != NULL) { -- cgit v1.2.3