]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Make sure gBS FreePool() is used to free the buffer always allocated by gBS AllocateP...
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 26 Jul 2010 16:20:34 +0000 (16:20 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 26 Jul 2010 16:20:34 +0000 (16:20 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10695 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/DxeServicesLib/DxeServicesLib.c
MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c

index d8e6b5cc4e404ccd86fa663d04fdeb9e860d0353..9cf845d6fc1bac276ea94401f66b2cf66ec8039b 100644 (file)
@@ -122,6 +122,7 @@ InternalGetSectionFromFv (
   EFI_STATUS                    Status;\r
   EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
   UINT32                        AuthenticationStatus;\r
+  VOID*                         TempBuffer;\r
 \r
   ASSERT (NameGuid != NULL);\r
   ASSERT (Buffer != NULL);\r
@@ -170,6 +171,17 @@ InternalGetSectionFromFv (
                     );\r
   }\r
 \r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // The found buffer by FV protocol is allocated by gBS AllocatePool() service. \r
+    // Copy the found buffer to the allocated buffer by AllocatePool().\r
+    // So, the returned buffer can be freed by FreePool().\r
+    //\r
+    TempBuffer = AllocateCopyPool (*Size, *Buffer);\r
+    gBS->FreePool (*Buffer);\r
+    *Buffer = TempBuffer;\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -312,7 +324,11 @@ GetSectionFromAnyFvByFileType  (
 \r
 Done:\r
   if (HandleBuffer != NULL) {  \r
-    FreePool(HandleBuffer);\r
+    //\r
+    // HandleBuffer is allocated by gBS AllocatePool() service. \r
+    // So, gBS FreePool() service is used to free HandleBuffer.\r
+    //\r
+    gBS->FreePool (HandleBuffer);\r
   }\r
 \r
   return Status;\r
@@ -435,8 +451,12 @@ GetSectionFromAnyFv  (
 \r
 Done:\r
   \r
-  if (HandleBuffer != NULL) {  \r
-    FreePool(HandleBuffer);\r
+  if (HandleBuffer != NULL) {\r
+    //\r
+    // HandleBuffer is allocated by gBS AllocatePool() service. \r
+    // So, gBS FreePool() service is used to free HandleBuffer.\r
+    //\r
+    gBS->FreePool (HandleBuffer);\r
   }\r
   return Status;\r
   \r
@@ -615,6 +635,7 @@ GetFileBufferByFilePath (
   EFI_FIRMWARE_VOLUME2_PROTOCOL     *FwVol;\r
   EFI_SECTION_TYPE                  SectionType;\r
   UINT8                             *ImageBuffer;\r
+  UINT8                             *TempBuffer;\r
   UINTN                             ImageBufferSize;\r
   EFI_FV_FILETYPE                   Type;\r
   EFI_FV_FILE_ATTRIBUTES            Attrib;\r
@@ -642,6 +663,7 @@ GetFileBufferByFilePath (
   FileInfo            = NULL;\r
   FileHandle          = NULL;\r
   ImageBuffer         = NULL;\r
+  TempBuffer          = NULL;\r
   ImageBufferSize     = 0;\r
   *AuthenticationStatus = 0;\r
   \r
@@ -702,6 +724,16 @@ GetFileBufferByFilePath (
                             AuthenticationStatus\r
                             );\r
         }\r
+        if (!EFI_ERROR (Status)) {\r
+          //\r
+          // The found buffer by FV protocol is allocated by gBS AllocatePool() service. \r
+          // Copy the found buffer to the allocated buffer by AllocatePool().\r
+          // Then, this returned buffer can be freed by FreePool().\r
+          //\r
+          TempBuffer = AllocateCopyPool (ImageBufferSize, ImageBuffer);\r
+          gBS->FreePool (ImageBuffer);\r
+          ImageBuffer = TempBuffer;\r
+        }\r
       }\r
     }\r
     goto Finish;\r
index ccd9df34d09b35a941de4964eb10461624425cb9..d6527ef3019c7ff70a0d5273fc1e3b3112c6153c 100644 (file)
@@ -96,7 +96,11 @@ PciSegmentLibConstructor (
     ASSERT (Descriptors->Desc != ACPI_END_TAG_DESCRIPTOR);\r
   }\r
 \r
-  FreePool(HandleBuffer);\r
+  //\r
+  // HandleBuffer is allocated by gBS AllocatePool() service. \r
+  // So, gBS FreePool() service is used to free HandleBuffer.\r
+  //\r
+  gBS->FreePool (HandleBuffer);\r
 \r
   return EFI_SUCCESS;\r
 }\r