From: Yao Jiewen Date: Fri, 25 Dec 2015 01:24:16 +0000 (+0000) Subject: ShellPkg: Fix memory leak in 'ShellOpenFileByName'. X-Git-Tag: edk2-stable201903~8135 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=dd17e3feb7080e174ed540d9d85ad2fb56bc669b ShellPkg: Fix memory leak in 'ShellOpenFileByName'. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yao Jiewen Reviewed-by: Qiu Shumin git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19524 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 44ac382980..9e815c56a6 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -673,6 +673,7 @@ ShellOpenFileByName( EFI_STATUS Status; EFI_FILE_INFO *FileInfo; CHAR16 *FileNameCopy; + EFI_STATUS Status2; // // ASSERT if FileName is NULL @@ -719,8 +720,12 @@ ShellOpenFileByName( FileInfo = FileFunctionMap.GetFileInfo(*FileHandle); ASSERT(FileInfo != NULL); FileInfo->Attribute = Attributes; - Status = FileFunctionMap.SetFileInfo(*FileHandle, FileInfo); + Status2 = FileFunctionMap.SetFileInfo(*FileHandle, FileInfo); FreePool(FileInfo); + if (EFI_ERROR (Status2)) { + gEfiShellProtocol->CloseFile(*FileHandle); + } + Status = Status2; } return (Status); }