IN UINTN Pages\r
)\r
{\r
+ EFI_STATUS Status;\r
+\r
ASSERT (Pages != 0);\r
- FreePool (Buffer);\r
+ if (!gEmuThunk->Free (Buffer)) {\r
+ // The Free thunk will not free memory allocated in emulated EFI memory.\r
+ // The assmuption is this was allocated directly by EFI. We need this as some \r
+ // times protocols or EFI BootServices can return dynamically allocated buffers.\r
+ Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
}\r
\r
/**\r
IN UINTN Alignment\r
)\r
{\r
+ EFI_STATUS Status;\r
VOID *Memory;\r
UINTN AlignedMemory;\r
UINTN AlignmentMask;\r
//\r
// Free first unaligned page(s).\r
//\r
- FreePool (Memory);\r
+ FreePages (Memory, UnalignedPages);\r
}\r
Memory = (VOID *) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));\r
UnalignedPages = RealPages - Pages - UnalignedPages;\r
//\r
// Free last unaligned page(s).\r
//\r
- FreePool (Memory);\r
+ FreePages (Memory, UnalignedPages);\r
}\r
} else {\r
//\r
IN UINTN Pages\r
)\r
{\r
- ASSERT (Pages != 0);\r
-\r
- FreePool (Buffer);\r
+ FreePages (Buffer, Pages);\r
}\r
\r
/**\r
IN VOID *Buffer\r
)\r
{\r
- EFI_STATUS Status;\r
- \r
+ EFI_STATUS Status;\r
+\r
if (!gEmuThunk->Free (Buffer)) {\r
// The Free thunk will not free memory allocated in emulated EFI memory.\r
// The assmuption is this was allocated directly by EFI. We need this as some \r
// times protocols or EFI BootServices can return dynamically allocated buffers.\r
- gBS->FreePool (Buffer);\r
+ Status = gBS->FreePool (Buffer);\r
+ ASSERT_EFI_ERROR (Status);\r
}\r
}\r
\r