From ae315cc26984d308dbe07b8e01dea7c56a78f79d Mon Sep 17 00:00:00 2001 From: Jaben Carsey Date: Tue, 5 Aug 2014 23:16:39 +0000 Subject: Fix the use of ASSERT and other fixes to memory allocation failures (like free before return for errors) Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey Reviewed-by: Erik Bjorge git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15759 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/UefiShellCommandLib/UefiShellCommandLib.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c') diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index ef5acd7da8..ebb84dd55e 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1392,7 +1392,9 @@ ShellCommandUpdateMapping ( // Get all Device Paths // DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count); - ASSERT(DevicePathList != NULL); + if (DevicePathList == NULL) { + return (EFI_OUT_OF_RESOURCES); + } for (Count = 0 ; HandleList[Count] != NULL ; Count++) { DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]); @@ -1408,7 +1410,7 @@ ShellCommandUpdateMapping ( // // Assign new Mappings to remainders // - for (Count = 0 ; HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) { + for (Count = 0 ; !EFI_ERROR(Status) && HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) { // // Skip ones that already have // @@ -1419,7 +1421,10 @@ ShellCommandUpdateMapping ( // Get default name // NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem); - ASSERT(NewDefaultName != NULL); + if (NewDefaultName == NULL) { + Status = EFI_OUT_OF_RESOURCES; + break; + } // // Call shell protocol SetMap function now... @@ -1496,11 +1501,14 @@ ConvertEfiFileProtocolToShellHandle( } NewNode = AllocateZeroPool(sizeof(BUFFER_LIST)); if (NewNode == NULL) { + SHELL_FREE_NON_NULL(Buffer); return (NULL); } Buffer->FileHandle = (EFI_FILE_PROTOCOL*)Handle; Buffer->Path = StrnCatGrow(&Buffer->Path, NULL, Path, 0); if (Buffer->Path == NULL) { + SHELL_FREE_NON_NULL(NewNode); + SHELL_FREE_NON_NULL(Buffer); return (NULL); } NewNode->Buffer = Buffer; @@ -1638,7 +1646,6 @@ FreeBufferList ( ; BufferListEntry = (BUFFER_LIST *)GetFirstNode(&List->Link) ){ RemoveEntryList(&BufferListEntry->Link); - ASSERT(BufferListEntry->Buffer != NULL); if (BufferListEntry->Buffer != NULL) { FreePool(BufferListEntry->Buffer); } -- cgit v1.2.3