1. Use MemoryAllocationLib to replace boot services memory services functions in EdkModulePkg.
2. Added NULL pointer check before calling FreePool () to fix bugs when free memory. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2513 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -424,13 +424,9 @@ Returns:
|
||||
Variable = NextVariable;
|
||||
}
|
||||
|
||||
Status = gBS->AllocatePool (
|
||||
EfiBootServicesData,
|
||||
ValidBufferSize,
|
||||
(VOID **) &ValidBuffer
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
ValidBuffer = AllocatePool (ValidBufferSize);
|
||||
if (ValidBuffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
SetMem (ValidBuffer, ValidBufferSize, 0xff);
|
||||
@ -481,7 +477,7 @@ Returns:
|
||||
}
|
||||
}
|
||||
|
||||
gBS->FreePool (ValidBuffer);
|
||||
FreePool (ValidBuffer);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
*LastVariableOffset = 0;
|
||||
@ -1253,13 +1249,13 @@ Returns:
|
||||
*RemainingVariableStorageSize -= VariableSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Go to the next one
|
||||
//
|
||||
Variable = NextVariable;
|
||||
}
|
||||
|
||||
|
||||
ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@ -1308,14 +1304,9 @@ Returns:
|
||||
UINTN Index;
|
||||
UINT8 Data;
|
||||
|
||||
Status = gBS->AllocatePool (
|
||||
EfiRuntimeServicesData,
|
||||
sizeof (ESAL_VARIABLE_GLOBAL),
|
||||
(VOID **) &mVariableModuleGlobal
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
mVariableModuleGlobal = AllocateRuntimePool (sizeof (ESAL_VARIABLE_GLOBAL));
|
||||
if (mVariableModuleGlobal == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal[Physical].VariableServicesLock, EFI_TPL_NOTIFY);
|
||||
@ -1323,15 +1314,10 @@ Returns:
|
||||
//
|
||||
// Allocate memory for volatile variable store
|
||||
//
|
||||
Status = gBS->AllocatePool (
|
||||
EfiRuntimeServicesData,
|
||||
VARIABLE_STORE_SIZE + SCRATCH_SIZE,
|
||||
(VOID **) &VolatileVariableStore
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (mVariableModuleGlobal);
|
||||
return Status;
|
||||
VolatileVariableStore = AllocateRuntimePool (VARIABLE_STORE_SIZE + SCRATCH_SIZE);
|
||||
if (VolatileVariableStore == NULL) {
|
||||
FreePool (mVariableModuleGlobal);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
SetMem (VolatileVariableStore, VARIABLE_STORE_SIZE + SCRATCH_SIZE, 0xff);
|
||||
@ -1367,8 +1353,8 @@ Returns:
|
||||
|
||||
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (mVariableModuleGlobal);
|
||||
gBS->FreePool (VolatileVariableStore);
|
||||
FreePool (mVariableModuleGlobal);
|
||||
FreePool (VolatileVariableStore);
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@ -1378,8 +1364,8 @@ Returns:
|
||||
GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (mVariableModuleGlobal);
|
||||
gBS->FreePool (VolatileVariableStore);
|
||||
FreePool (mVariableModuleGlobal);
|
||||
FreePool (VolatileVariableStore);
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
//
|
||||
@ -1448,8 +1434,8 @@ Returns:
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (mVariableModuleGlobal);
|
||||
gBS->FreePool (VolatileVariableStore);
|
||||
FreePool (mVariableModuleGlobal);
|
||||
FreePool (VolatileVariableStore);
|
||||
return Status;
|
||||
}
|
||||
|
||||
@ -1473,8 +1459,8 @@ Returns:
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (mVariableModuleGlobal);
|
||||
gBS->FreePool (VolatileVariableStore);
|
||||
FreePool (mVariableModuleGlobal);
|
||||
FreePool (VolatileVariableStore);
|
||||
}
|
||||
|
||||
return Status;
|
||||
|
@ -52,6 +52,9 @@
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>BaseLib</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>MemoryAllocationLib</Keyword>
|
||||
</LibraryClass>
|
||||
</LibraryClassDefinitions>
|
||||
<SourceFiles>
|
||||
<Filename>Variable.h</Filename>
|
||||
|
@ -55,6 +55,9 @@
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>BaseLib</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>MemoryAllocationLib</Keyword>
|
||||
</LibraryClass>
|
||||
</LibraryClassDefinitions>
|
||||
<SourceFiles>
|
||||
<Filename>Variable.h</Filename>
|
||||
|
@ -1,20 +1,20 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
Copyright (c) 2006 - 2007, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
|
||||
reclaim.c
|
||||
|
||||
|
||||
Abstract:
|
||||
|
||||
|
||||
Handles non-volatile variable store garbage collection, using FTW
|
||||
(Fault Tolerant Write) protocol.
|
||||
|
||||
@ -82,7 +82,7 @@ GetFvbHandleByAddress (
|
||||
}
|
||||
}
|
||||
|
||||
gBS->FreePool (HandleBuffer);
|
||||
FreePool (HandleBuffer);
|
||||
return Status;
|
||||
}
|
||||
|
||||
@ -216,8 +216,8 @@ Returns:
|
||||
// Prepare for the variable data
|
||||
//
|
||||
FtwBufferSize = ((VARIABLE_STORE_HEADER *) ((UINTN) VariableBase))->Size;
|
||||
Status = gBS->AllocatePool (EfiRuntimeServicesData, FtwBufferSize, (VOID **) &FtwBuffer);
|
||||
if (EFI_ERROR (Status)) {
|
||||
FtwBuffer = AllocateRuntimePool (FtwBufferSize);
|
||||
if (FtwBuffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
@ -236,6 +236,6 @@ Returns:
|
||||
FtwBuffer
|
||||
);
|
||||
|
||||
gBS->FreePool (FtwBuffer);
|
||||
FreePool (FtwBuffer);
|
||||
return Status;
|
||||
}
|
||||
|
Reference in New Issue
Block a user