ShellPkg: Fix memory leak in function 'EfiShellSetCurDir' and 'EfiShellSetMap'.

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
This commit is contained in:
Yao Jiewen 2015-12-25 01:52:56 +00:00 committed by shenshushi
parent 990046ca42
commit 4aec9fe30f
1 changed files with 9 additions and 0 deletions

View File

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