From 5772d0f540cd770dccb37c8742f173c57109bea7 Mon Sep 17 00:00:00 2001 From: Qiu Shumin Date: Wed, 23 Dec 2015 05:36:10 +0000 Subject: [PATCH] ShellPkg: Fix memory leak in SimpleTextOutput on file. Free 'SimpleTextOut->Mode' buffer before 'SimpleTextOut' is free. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin Reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19480 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Application/Shell/ConsoleWrappers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Application/Shell/ConsoleWrappers.c b/ShellPkg/Application/Shell/ConsoleWrappers.c index 04a7513a33..46af141eba 100644 --- a/ShellPkg/Application/Shell/ConsoleWrappers.c +++ b/ShellPkg/Application/Shell/ConsoleWrappers.c @@ -484,7 +484,8 @@ CreateSimpleTextOutOnFile( *HandleLocation = ProtocolToReturn->TheHandle; return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)ProtocolToReturn); } else { - FreePool(ProtocolToReturn); + SHELL_FREE_NON_NULL(ProtocolToReturn->SimpleTextOut.Mode); + SHELL_FREE_NON_NULL(ProtocolToReturn); return (NULL); } } @@ -511,6 +512,7 @@ CloseSimpleTextOutOnFile( ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)SimpleTextOut)->TheHandle, &gEfiSimpleTextOutProtocolGuid, &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)SimpleTextOut)->SimpleTextOut)); + FreePool(SimpleTextOut->Mode); FreePool(SimpleTextOut); return (Status); }