Fix memory leak issues.

Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13428 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
niruiyu 2012-06-06 08:41:58 +00:00
parent d6f19057f0
commit 2d1f3dd497
2 changed files with 11 additions and 2 deletions

View File

@ -825,6 +825,7 @@ BdsLibGetVariableAndSize (
//
Buffer = AllocateZeroPool (BufferSize);
if (Buffer == NULL) {
*VariableSize = 0;
return NULL;
}
//
@ -832,10 +833,15 @@ BdsLibGetVariableAndSize (
//
Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
if (EFI_ERROR (Status)) {
FreePool (Buffer);
BufferSize = 0;
Buffer = NULL;
}
}
ASSERT (((Buffer == NULL) && (BufferSize == 0)) ||
((Buffer != NULL) && (BufferSize != 0))
);
*VariableSize = BufferSize;
return Buffer;
}

View File

@ -76,6 +76,8 @@ OrderLegacyBootOption4SameType (
*EnBootOptionCount = 0;
Index = 0;
ASSERT (BbsIndexArray != NULL);
ASSERT (DeviceTypeArray != NULL);
ASSERT (*EnBootOption != NULL);
ASSERT (*DisBootOption != NULL);
@ -84,7 +86,7 @@ OrderLegacyBootOption4SameType (
UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]);
InitializeListHead (&List);
BootOption = BdsLibVariableToOption (&List, OptionName);
ASSERT_EFI_ERROR (BootOption != NULL);
ASSERT (BootOption != NULL);
if ((DevicePathType (BootOption->DevicePath) == BBS_DEVICE_PATH) &&
(DevicePathSubType (BootOption->DevicePath) == BBS_BBS_DP)) {
@ -111,6 +113,7 @@ OrderLegacyBootOption4SameType (
//
StartPosition = BootOrderSize / sizeof (UINT16);
NewBootOption = AllocatePool (DevOrderCount * sizeof (UINT16));
ASSERT (NewBootOption != NULL);
while (DevOrderCount-- != 0) {
for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
if (BbsIndexArray[Index] == (DevOrder[DevOrderCount] & 0xFF)) {
@ -191,7 +194,7 @@ GroupMultipleLegacyBootOption4SameType (
UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]);
InitializeListHead (&List);
BootOption = BdsLibVariableToOption (&List, OptionName);
ASSERT_EFI_ERROR (BootOption != NULL);
ASSERT (BootOption != NULL);
if ((DevicePathType (BootOption->DevicePath) == BBS_DEVICE_PATH) &&
(DevicePathSubType (BootOption->DevicePath) == BBS_BBS_DP)) {