From 06e5ae774ecf716216b325c432e70f7368c0d694 Mon Sep 17 00:00:00 2001 From: Qiu Shumin Date: Wed, 23 Dec 2015 05:44:19 +0000 Subject: [PATCH] ShellPkg: Fix memory leak in ShellProtocol. 1. Close unused file handle. 2. Free the local allocated buffer function returned. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin Reviewed-by: Jaben Carsey Reviewed-by: Ruiyu Ni git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19481 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Application/Shell/ShellProtocol.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c index def3bd35c2..2ddb64d8c7 100644 --- a/ShellPkg/Application/Shell/ShellProtocol.c +++ b/ShellPkg/Application/Shell/ShellProtocol.c @@ -1361,6 +1361,7 @@ EfiShellDeleteFileByName( // // now delete the file // + ShellFileHandleRemove(FileHandle); return (ShellInfoObject.NewEfiShellProtocol->DeleteFile(FileHandle)); } @@ -2338,6 +2339,8 @@ ShellSearchHandle( // recurse with the next part of the pattern // Status = ShellSearchHandle(NextFilePatternStart, UnicodeCollation, ShellInfoNode->Handle, FileList, ShellInfoNode, MapName); + EfiShellClose(ShellInfoNode->Handle); + ShellInfoNode->Handle = NULL; } } else if (!EFI_ERROR(Status)) { // @@ -2456,6 +2459,7 @@ EfiShellFindFiles( ; PatternCurrentLocation++); PatternCurrentLocation++; Status = ShellSearchHandle(PatternCurrentLocation, gUnicodeCollation, RootFileHandle, FileList, NULL, MapName); + EfiShellClose(RootFileHandle); } FreePool(RootDevicePath); } @@ -3260,6 +3264,7 @@ EfiShellGetAlias( if (Volatile == NULL) { GetVariable2 (AliasLower, &gShellAliasGuid, (VOID **)&AliasVal, NULL); + FreePool(AliasLower); return (AddBufferToFreeList(AliasVal)); } RetSize = 0; @@ -3273,6 +3278,7 @@ EfiShellGetAlias( if (RetVal != NULL) { FreePool(RetVal); } + FreePool(AliasLower); return (NULL); } if ((EFI_VARIABLE_NON_VOLATILE & Attribs) == EFI_VARIABLE_NON_VOLATILE) { -- 2.39.5