Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its implementation only check if a pointer is NULL. If a garbage pointer is passed in, the gBS->FreePool will still ASSERT in debug build and return error code.

It is recommended that module writer should keep track how a pointer is allocated and free it after use.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6306 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12
2008-10-30 07:32:46 +00:00
parent bb1d8ee669
commit 676df92c2c
27 changed files with 652 additions and 410 deletions

View File

@@ -173,7 +173,7 @@ BdsLibBootViaBootOption (
Status = BdsLibUpdateFvFileDevicePath (&DevicePath, &gEfiShellFileGuid);
if (!EFI_ERROR(Status)) {
if (Option->DevicePath != NULL) {
SafeFreePool(Option->DevicePath);
FreePool(Option->DevicePath);
}
Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));
CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
@@ -186,7 +186,7 @@ BdsLibBootViaBootOption (
//
// free the temporary device path created by BdsLibUpdateFvFileDevicePath()
//
SafeFreePool (DevicePath);
FreePool (DevicePath);
DevicePath = Option->DevicePath;
}
@@ -358,7 +358,7 @@ BdsExpandPartitionPartialDevicePathToFull (
// Come here means the first instance is not matched
//
NeedAdjust = TRUE;
SafeFreePool(Instance);
FreePool(Instance);
} while (TempNewDevicePath != NULL);
if (DeviceExist) {
@@ -378,14 +378,14 @@ BdsExpandPartitionPartialDevicePathToFull (
//
TempNewDevicePath = CachedDevicePath;
CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, Instance );
SafeFreePool (TempNewDevicePath);
FreePool (TempNewDevicePath);
//
// Second, append the remaining parth after the matched instance
//
TempNewDevicePath = CachedDevicePath;
CachedDevicePath = AppendDevicePathInstance (Instance, CachedDevicePath );
SafeFreePool (TempNewDevicePath);
FreePool (TempNewDevicePath);
//
// Save the matching Device Path so we don't need to do a connect all next time
//
@@ -398,8 +398,8 @@ BdsExpandPartitionPartialDevicePathToFull (
);
}
SafeFreePool (Instance);
SafeFreePool (CachedDevicePath);
FreePool (Instance);
FreePool (CachedDevicePath);
return FullDevicePath;
}
}
@@ -444,15 +444,15 @@ BdsExpandPartitionPartialDevicePathToFull (
if (BdsLibMatchDevicePaths (CachedDevicePath, BlockIoDevicePath)) {
TempNewDevicePath = CachedDevicePath;
CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, BlockIoDevicePath);
SafeFreePool(TempNewDevicePath);
FreePool(TempNewDevicePath);
TempNewDevicePath = CachedDevicePath;
CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);
SafeFreePool(TempNewDevicePath);
FreePool(TempNewDevicePath);
} else {
TempNewDevicePath = CachedDevicePath;
CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);
SafeFreePool(TempNewDevicePath);
FreePool(TempNewDevicePath);
}
//
// Here limit the device path instance number to 12, which is max number for a system support 3 IDE controller
@@ -496,8 +496,10 @@ BdsExpandPartitionPartialDevicePathToFull (
}
}
SafeFreePool (CachedDevicePath);
SafeFreePool (BlockIoBuffer);
FreePool (CachedDevicePath);
if (BlockIoBuffer != NULL) {
FreePool (BlockIoBuffer);
}
return FullDevicePath;
}
@@ -649,7 +651,7 @@ BdsLibDeleteOptionFromHandle (
);
if (BootOptionVar == NULL) {
SafeFreePool (BootOrder);
FreePool (BootOrder);
return EFI_OUT_OF_RESOURCES;
}
@@ -665,11 +667,11 @@ BdsLibDeleteOptionFromHandle (
if ((OptionDevicePathSize == DevicePathSize) &&
(CompareMem (DevicePath, OptionDevicePath, DevicePathSize) == 0)) {
BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);
SafeFreePool (BootOptionVar);
FreePool (BootOptionVar);
break;
}
SafeFreePool (BootOptionVar);
FreePool (BootOptionVar);
Index++;
}
@@ -684,7 +686,7 @@ BdsLibDeleteOptionFromHandle (
BootOrder
);
SafeFreePool (BootOrder);
FreePool (BootOrder);
return Status;
}
@@ -741,7 +743,7 @@ BdsDeleteAllInvalidEfiBootOption (
&BootOptionSize
);
if (NULL == BootOptionVar) {
SafeFreePool (BootOrder);
FreePool (BootOrder);
return EFI_OUT_OF_RESOURCES;
}
@@ -755,7 +757,7 @@ BdsDeleteAllInvalidEfiBootOption (
//
if ((DevicePathType (OptionDevicePath) == BBS_DEVICE_PATH) &&
(DevicePathSubType (OptionDevicePath) == BBS_BBS_DP)) {
SafeFreePool (BootOptionVar);
FreePool (BootOptionVar);
Index++;
continue;
}
@@ -777,7 +779,7 @@ BdsDeleteAllInvalidEfiBootOption (
BootOrder[Index] = 0xffff;
}
SafeFreePool (BootOptionVar);
FreePool (BootOptionVar);
Index++;
}
@@ -799,7 +801,7 @@ BdsDeleteAllInvalidEfiBootOption (
BootOrder
);
SafeFreePool (BootOrder);
FreePool (BootOrder);
return Status;
}
@@ -963,7 +965,7 @@ BdsLibEnumerateAllBootOption (
}
if (NumberBlockIoHandles != 0) {
SafeFreePool (BlockIoHandles);
FreePool (BlockIoHandles);
}
//
@@ -1025,7 +1027,7 @@ BdsLibEnumerateAllBootOption (
}
if (NumberFileSystemHandles != 0) {
SafeFreePool (FileSystemHandles);
FreePool (FileSystemHandles);
}
//
@@ -1048,7 +1050,7 @@ BdsLibEnumerateAllBootOption (
}
if (NumberSimpleNetworkHandles != 0) {
SafeFreePool (SimpleNetworkHandles);
FreePool (SimpleNetworkHandles);
}
//
@@ -1102,7 +1104,7 @@ BdsLibEnumerateAllBootOption (
}
if (FvHandleCount != 0) {
SafeFreePool (FvHandleBuffer);
FreePool (FvHandleBuffer);
}
//
// Make sure every boot only have one time
@@ -1307,7 +1309,7 @@ BdsLibGetBootableHandle (
BlockIo->Media->BlockSize,
Buffer
);
SafeFreePool(Buffer);
FreePool(Buffer);
}
}
@@ -1320,6 +1322,8 @@ BdsLibGetBootableHandle (
// Try to locate the USB node device path first, if fail then use its previour PCI node to search
//
DupDevicePath = DuplicateDevicePath (DevicePath);
ASSERT (DupDevicePath != NULL);
UpdatedDevicePath = DupDevicePath;
Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);
//
@@ -1379,9 +1383,11 @@ BdsLibGetBootableHandle (
}
}
SafeFreePool(DupDevicePath);
FreePool(DupDevicePath);
SafeFreePool(SimpleFileSystemHandles);
if (SimpleFileSystemHandles != NULL) {
FreePool(SimpleFileSystemHandles);
}
return ReturnHandle;
}
@@ -1640,7 +1646,7 @@ BdsLibIsValidEFIBootOptDevicePath (
return TRUE;
} else {
if (Status == EFI_SUCCESS) {
SafeFreePool (TempDevicePath);
FreePool (TempDevicePath);
}
return FALSE;
}
@@ -1885,8 +1891,10 @@ BdsLibUpdateFvFileDevicePath (
FoundFvHandle = FvHandleBuffer[Index];
break;
}
SafeFreePool (FvHandleBuffer);
if (FvHandleBuffer != NULL) {
FreePool (FvHandleBuffer);
}
}
if (FindFvFile) {

View File

@@ -176,7 +176,7 @@ BdsLibConnectDevicePath (
} while (DevicePath != NULL);
if (CopyOfDevicePath != NULL) {
SafeFreePool (CopyOfDevicePath);
FreePool (CopyOfDevicePath);
}
//
// All handle with DevicePath exists in the handle database
@@ -220,7 +220,9 @@ BdsLibConnectAllEfi (
Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
}
SafeFreePool (HandleBuffer);
if (HandleBuffer != NULL) {
FreePool (HandleBuffer);
}
return EFI_SUCCESS;
}
@@ -263,7 +265,9 @@ BdsLibDisconnectAllEfi (
Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
}
SafeFreePool (HandleBuffer);
if (HandleBuffer != NULL) {
FreePool (HandleBuffer);
}
return EFI_SUCCESS;
}

View File

@@ -126,7 +126,9 @@ BdsLibUpdateConsoleVariable (
//
TempNewDevicePath = NewDevicePath;
NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath);
SafeFreePool(TempNewDevicePath);
if (TempNewDevicePath != NULL) {
FreePool(TempNewDevicePath);
}
}
}
@@ -157,10 +159,16 @@ BdsLibUpdateConsoleVariable (
);
if (VarConsole == NewDevicePath) {
SafeFreePool(VarConsole);
if (VarConsole != NULL) {
FreePool(VarConsole);
}
} else {
SafeFreePool(VarConsole);
SafeFreePool(NewDevicePath);
if (VarConsole != NULL) {
FreePool(VarConsole);
}
if (NewDevicePath) {
FreePool(NewDevicePath);
}
}
return EFI_SUCCESS;
@@ -258,10 +266,10 @@ BdsLibConnectConsoleVariable (
DeviceExist = TRUE;
}
}
SafeFreePool(Instance);
FreePool(Instance);
} while (CopyOfDevicePath != NULL);
SafeFreePool (StartDevicePath);
FreePool (StartDevicePath);
if (!DeviceExist) {
return EFI_NOT_FOUND;
@@ -312,7 +320,10 @@ BdsLibConnectAllConsoles (
BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);
}
SafeFreePool(HandleBuffer);
if (HandleBuffer != NULL) {
FreePool(HandleBuffer);
HandleBuffer = NULL;
}
gBS->LocateHandleBuffer (
ByProtocol,
@@ -331,7 +342,9 @@ BdsLibConnectAllConsoles (
BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);
}
SafeFreePool(HandleBuffer);
if (HandleBuffer != NULL) {
FreePool(HandleBuffer);
}
//
// Connect all console variables

View File

@@ -304,25 +304,27 @@ BdsLibRegisterNewOption (
//
// Got the option, so just return
//
SafeFreePool (OptionPtr);
SafeFreePool (TempOptionPtr);
FreePool (OptionPtr);
FreePool (TempOptionPtr);
return EFI_SUCCESS;
} else {
//
// Option description changed, need update.
//
UpdateDescription = TRUE;
SafeFreePool (OptionPtr);
FreePool (OptionPtr);
break;
}
}
SafeFreePool (OptionPtr);
FreePool (OptionPtr);
}
OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String);
OptionSize += GetDevicePathSize (DevicePath);
OptionPtr = AllocateZeroPool (OptionSize);
ASSERT (OptionPtr != NULL);
TempPtr = OptionPtr;
*(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;
TempPtr += sizeof (UINT32);
@@ -361,12 +363,12 @@ BdsLibRegisterNewOption (
// Return if only need to update a changed description or fail to set option.
//
if (EFI_ERROR (Status) || UpdateDescription) {
SafeFreePool (OptionPtr);
SafeFreePool (TempOptionPtr);
FreePool (OptionPtr);
FreePool (TempOptionPtr);
return Status;
}
SafeFreePool (OptionPtr);
FreePool (OptionPtr);
//
// Update the option order variable
@@ -384,7 +386,7 @@ BdsLibRegisterNewOption (
sizeof (UINT16),
&BootOrderEntry
);
SafeFreePool (TempOptionPtr);
FreePool (TempOptionPtr);
return Status;
}
@@ -393,6 +395,8 @@ BdsLibRegisterNewOption (
//
OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ;
OptionOrderPtr = AllocateZeroPool ( OrderItemNum * sizeof (UINT16));
ASSERT (OptionOrderPtr!= NULL);
CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16));
OptionOrderPtr[Index] = RegisterOptionNumber;
@@ -404,8 +408,8 @@ BdsLibRegisterNewOption (
OrderItemNum * sizeof (UINT16),
OptionOrderPtr
);
SafeFreePool (TempOptionPtr);
SafeFreePool (OptionOrderPtr);
FreePool (TempOptionPtr);
FreePool (OptionOrderPtr);
return Status;
}
@@ -525,12 +529,12 @@ BdsLibVariableToOption (
//
if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {
InsertTailList (BdsCommonOptionList, &Option->Link);
SafeFreePool (Variable);
FreePool (Variable);
return Option;
}
SafeFreePool (Variable);
SafeFreePool (Option);
FreePool (Variable);
FreePool (Option);
return NULL;
}
@@ -591,7 +595,7 @@ BdsLibBuildOptionFromVar (
}
SafeFreePool (OptionOrder);
FreePool (OptionOrder);
return EFI_SUCCESS;
}
@@ -716,9 +720,11 @@ BdsLibDelPartMatchInstance (
//
TempNewDevicePath = NewDevicePath;
NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);
SafeFreePool(TempNewDevicePath);
if (TempNewDevicePath != NULL) {
FreePool(TempNewDevicePath);
}
}
SafeFreePool(Instance);
FreePool(Instance);
Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
InstanceSize -= END_DEVICE_PATH_LENGTH;
}
@@ -766,11 +772,11 @@ BdsLibMatchDevicePaths (
// return success
//
if (CompareMem (Single, DevicePathInst, Size) == 0) {
SafeFreePool (DevicePathInst);
FreePool (DevicePathInst);
return TRUE;
}
SafeFreePool (DevicePathInst);
FreePool (DevicePathInst);
DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
}
@@ -952,8 +958,8 @@ SetupResetReminder (
IfrLibCreatePopUp (2, &Key, StringBuffer1, StringBuffer2);
} while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
SafeFreePool (StringBuffer1);
SafeFreePool (StringBuffer2);
FreePool (StringBuffer1);
FreePool (StringBuffer2);
//
// If the user hits the YES Response key, reset
//
@@ -1014,7 +1020,7 @@ BdsLibGetImageHeader (
&Root
);
if (EFI_ERROR (Status)) {
Root = NULL;
Root = NULL;
goto Done;
}
@@ -1043,13 +1049,14 @@ BdsLibGetImageHeader (
break;
}
if (Status != EFI_BUFFER_TOO_SMALL) {
FreePool (Info);
goto Done;
}
SafeFreePool (Info);
FreePool (Info);
} while (TRUE);
FileSize = Info->FileSize;
SafeFreePool (Info);
FreePool (Info);
//
// Read dos header

View File

@@ -45,7 +45,7 @@ ReallocatePool (
CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
}
SafeFreePool (OldPool);
FreePool (OldPool);
}
return NewPool;
@@ -108,7 +108,7 @@ CatPrint (
Str->len = StringSize - sizeof (UINT16);
}
SafeFreePool (AppendStr);
FreePool (AppendStr);
return Str->str;
}
@@ -1594,7 +1594,7 @@ DevicePathToStr (
//
// Shrink pool used for string allocation
//
SafeFreePool (DevPath);
FreePool (DevPath);
Done:
NewSize = (Str.len + 1) * sizeof (CHAR16);

View File

@@ -467,7 +467,9 @@ EnableQuietBootEx (
// Currently only support BMP format.
//
if (Format != EfiBadgingFormatBMP) {
SafeFreePool (ImageData);
if (ImageData != NULL) {
FreePool (ImageData);
}
continue;
}
} else {
@@ -494,7 +496,9 @@ EnableQuietBootEx (
&Width
);
if (EFI_ERROR (Status)) {
SafeFreePool (ImageData);
if (ImageData != NULL) {
FreePool (ImageData);
}
if (Badging == NULL) {
return Status;
} else {
@@ -589,8 +593,12 @@ EnableQuietBootEx (
}
}
SafeFreePool (ImageData);
SafeFreePool (Blt);
if (ImageData != NULL) {
FreePool (ImageData);
}
if (Blt != NULL) {
FreePool (Blt);
}
if (Badging == NULL) {
break;
@@ -780,8 +788,8 @@ Print (
Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
if (Blt->Image.Bitmap == NULL) {
SafeFreePool (Blt);
SafeFreePool (Buffer);
FreePool (Blt);
FreePool (Buffer);
return EFI_OUT_OF_RESOURCES;
}
@@ -824,15 +832,23 @@ Print (
);
}
SafeFreePool (RowInfoArray);
SafeFreePool (Blt->Image.Bitmap);
if (RowInfoArray != NULL) {
FreePool (RowInfoArray);
}
if (Blt->Image.Bitmap != NULL) {
FreePool (Blt->Image.Bitmap);
}
} else {
Status = EFI_UNSUPPORTED;
}
Error:
SafeFreePool (Blt);
SafeFreePool (FontInfo);
if (Blt != NULL) {
FreePool (Blt);
}
if (FontInfo != NULL) {
FreePool (FontInfo);
}
FreePool (Buffer);
if (EFI_ERROR (Status)) {