ShellPkg/UefiShellLib: Handle memory allocation failure

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
This commit is contained in:
Ruiyu Ni 2016-07-13 17:39:37 +08:00
parent 28d447f9bd
commit 2efafabf41
1 changed files with 10 additions and 2 deletions

View File

@ -2021,6 +2021,7 @@ InternalCommandLineParse (
UINTN Count;
CONST CHAR16 *TempPointer;
UINTN CurrentValueSize;
CHAR16 *NewValue;
CurrentItemPackage = NULL;
GetItemValue = 0;
@ -2119,8 +2120,15 @@ InternalCommandLineParse (
// get the item VALUE for a previous flag
//
CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);
ASSERT(CurrentItemPackage->Value != NULL);
NewValue = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);
if (NewValue == NULL) {
SHELL_FREE_NON_NULL (CurrentItemPackage->Value);
SHELL_FREE_NON_NULL (CurrentItemPackage);
ShellCommandLineFreeVarList (*CheckPackage);
*CheckPackage = NULL;
return EFI_OUT_OF_RESOURCES;
}
CurrentItemPackage->Value = NewValue;
if (ValueSize == 0) {
StrCpyS( CurrentItemPackage->Value,
CurrentValueSize/sizeof(CHAR16),