]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Fix memory leak in function 'EfiShellSetCurDir' and 'EfiShellSetMap'.
authorYao Jiewen <Jiewen.Yao@intel.com>
Fri, 25 Dec 2015 01:52:56 +0000 (01:52 +0000)
committershenshushi <shenshushi@Edk2>
Fri, 25 Dec 2015 01:52:56 +0000 (01:52 +0000)
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yao Jiewen <Jiewen.Yao@intel.com>
Reviewed-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19529 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/ShellProtocol.c

index a6bf9c29b4f6a8c590d8199d99701bbeb996d8a2..22d398757fb59d64418c3610a35f6d947ace9d4e 100644 (file)
@@ -185,6 +185,9 @@ EfiShellSetMap(
        ){\r
           if (StringNoCaseCompare(&MapListNode->MapName, &Mapping) == 0) {\r
             RemoveEntryList(&MapListNode->Link);\r
+            SHELL_FREE_NON_NULL(MapListNode->DevicePath);\r
+            SHELL_FREE_NON_NULL(MapListNode->MapName);\r
+            SHELL_FREE_NON_NULL(MapListNode->CurrentDirectoryPath);\r
             FreePool(MapListNode);\r
             return (EFI_SUCCESS);\r
           }\r
@@ -2951,6 +2954,8 @@ EfiShellSetCurDir(
     }\r
 \r
     if (MapListItem == NULL) {\r
+      FreePool (DirectoryName);\r
+      SHELL_FREE_NON_NULL(MapName);\r
       return (EFI_NOT_FOUND);\r
     }\r
 \r
@@ -2967,6 +2972,7 @@ EfiShellSetCurDir(
         ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r
         MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName+StrLen(MapName), 0);\r
       }\r
+      FreePool (MapName);\r
     } else {\r
       ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r
       MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0);\r
@@ -2982,6 +2988,7 @@ EfiShellSetCurDir(
     // cant have a mapping in the directory...\r
     //\r
     if (StrStr(DirectoryName, L":") != NULL) {\r
+      FreePool (DirectoryName);\r
       return (EFI_INVALID_PARAMETER);\r
     }\r
     //\r
@@ -2989,6 +2996,7 @@ EfiShellSetCurDir(
     //\r
     MapListItem = ShellCommandFindMapItem(FileSystem);\r
     if (MapListItem == NULL) {\r
+      FreePool (DirectoryName);\r
       return (EFI_INVALID_PARAMETER);\r
     }\r
 //    gShellCurDir = MapListItem;\r
@@ -3013,6 +3021,7 @@ EfiShellSetCurDir(
       }\r
     }\r
   }\r
+  FreePool (DirectoryName);\r
   //\r
   // if updated the current directory then update the environment variable\r
   //\r