public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH 1/4] MdeModulePkg/SpiBus: Free handle buffers after LocateHandleBuffer
@ 2025-06-11  4:03 Dongyan Qian
  2025-06-11  4:03 ` [edk2-devel] [PATCH 2/4] NetworkPkg/HttpUtilitiesDxe: " Dongyan Qian
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dongyan Qian @ 2025-06-11  4:03 UTC (permalink / raw)
  To: devel

Fix memory leaks by adding missing FreePool calls:
release SpiHcHandles in SpiBusEntry exit path.

REF: https://uefi.org/sites/default/files/resources/UEFI_Spec_Final_2.11.pdf
Chapter 7.3.15: "Services - Boot Services.LocateHandleBuffer":
It is the caller's responsibility to call the Boot Service.FreePool when
the caller no longer requires the contents of Buffer.

Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
---
 MdeModulePkg/Bus/Spi/SpiBus/SpiBusDxe.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MdeModulePkg/Bus/Spi/SpiBus/SpiBusDxe.c b/MdeModulePkg/Bus/Spi/SpiBus/SpiBusDxe.c
index a2b77e79c6..37ce3e14ad 100644
--- a/MdeModulePkg/Bus/Spi/SpiBus/SpiBusDxe.c
+++ b/MdeModulePkg/Bus/Spi/SpiBus/SpiBusDxe.c
@@ -193,6 +193,13 @@ SpiBusEntry (
   }
 
 Exit:
+  //
+  // Free the buffer containing the list of handles from the handle database
+  //
+  if (SpiHcHandles != NULL) {
+    gBS->FreePool (SpiHcHandles);
+  }
+
   DEBUG ((DEBUG_VERBOSE, "%a - EXIT (Status = %r)\n", __func__, Status));
   return Status;
 }
-- 
2.49.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#121415): https://edk2.groups.io/g/devel/message/121415
Mute This Topic: https://groups.io/mt/113583367/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [edk2-devel] [PATCH 2/4] NetworkPkg/HttpUtilitiesDxe: Free handle buffers after LocateHandleBuffer
  2025-06-11  4:03 [edk2-devel] [PATCH 1/4] MdeModulePkg/SpiBus: Free handle buffers after LocateHandleBuffer Dongyan Qian
@ 2025-06-11  4:03 ` Dongyan Qian
  2025-06-11  4:03 ` [edk2-devel] [PATCH 3/4] PrmPkg/DxePrmContextBufferLib: " Dongyan Qian
  2025-06-11  4:03 ` [edk2-devel] [PATCH 4/4] RedfishPkg/RedfishConfigHandler: " Dongyan Qian
  2 siblings, 0 replies; 4+ messages in thread
From: Dongyan Qian @ 2025-06-11  4:03 UTC (permalink / raw)
  To: devel

Fix memory leaks by adding missing FreePool calls:
free HandleBuffer in HttpUtilitiesDxeUnload.

REF: https://uefi.org/sites/default/files/resources/UEFI_Spec_Final_2.11.pdf
Chapter 7.3.15: "Services - Boot Services.LocateHandleBuffer":
It is the caller's responsibility to call the Boot Service.FreePool when
the caller no longer requires the contents of Buffer.

Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
---
 NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c
index a3e1ea4691..308d3b1ce9 100644
--- a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c
+++ b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.c
@@ -59,7 +59,7 @@ HttpUtilitiesDxeUnload (
                     EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
                     );
     if (EFI_ERROR (Status)) {
-      return Status;
+      goto Exit;
     }
 
     //
@@ -72,10 +72,15 @@ HttpUtilitiesDxeUnload (
                     NULL
                     );
     if (EFI_ERROR (Status)) {
-      return Status;
+      goto Exit;
     }
   }
 
+Exit:
+  if (HandleBuffer != NULL) {
+    gBS->FreePool (HandleBuffer);
+  }
+
   return EFI_SUCCESS;
 }
 
-- 
2.49.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#121416): https://edk2.groups.io/g/devel/message/121416
Mute This Topic: https://groups.io/mt/113583368/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [edk2-devel] [PATCH 3/4] PrmPkg/DxePrmContextBufferLib: Free handle buffers after LocateHandleBuffer
  2025-06-11  4:03 [edk2-devel] [PATCH 1/4] MdeModulePkg/SpiBus: Free handle buffers after LocateHandleBuffer Dongyan Qian
  2025-06-11  4:03 ` [edk2-devel] [PATCH 2/4] NetworkPkg/HttpUtilitiesDxe: " Dongyan Qian
@ 2025-06-11  4:03 ` Dongyan Qian
  2025-06-11  4:03 ` [edk2-devel] [PATCH 4/4] RedfishPkg/RedfishConfigHandler: " Dongyan Qian
  2 siblings, 0 replies; 4+ messages in thread
From: Dongyan Qian @ 2025-06-11  4:03 UTC (permalink / raw)
  To: devel

Fix memory leaks by adding missing FreePool calls:
cleanup HandleBuffer in GetModuleContextBuffers.

REF: https://uefi.org/sites/default/files/resources/UEFI_Spec_Final_2.11.pdf
Chapter 7.3.15: "Services - Boot Services.LocateHandleBuffer":
It is the caller's responsibility to call the Boot Service.FreePool when
the caller no longer requires the contents of Buffer.

Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
---
 .../DxePrmContextBufferLib.c                      | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c
index a6ad141556..357d2c0438 100644
--- a/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c
+++ b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c
@@ -127,13 +127,15 @@ GetModuleContextBuffers (
             ));
 
           *PrmModuleContextBuffers = &PrmConfigProtocol->ModuleContextBuffers;
-          return EFI_SUCCESS;
+          Status = EFI_SUCCESS;
+          goto Exit;
         }
       } else {
         Status = FindContextBufferInModuleBuffers (Guid, &PrmConfigProtocol->ModuleContextBuffers, &PrmContextBuffer);
         if (!EFI_ERROR (Status)) {
           *PrmModuleContextBuffers = &PrmConfigProtocol->ModuleContextBuffers;
-          return EFI_SUCCESS;
+          Status = EFI_SUCCESS;
+          goto Exit;
         }
       }
     }
@@ -147,7 +149,14 @@ GetModuleContextBuffers (
     Guid
     ));
 
-  return EFI_NOT_FOUND;
+  Status = EFI_NOT_FOUND;
+
+Exit:
+  if (HandleBuffer != NULL) {
+    gBS->FreePool (HandleBuffer);
+  }
+
+  return Status;
 }
 
 /**
-- 
2.49.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#121414): https://edk2.groups.io/g/devel/message/121414
Mute This Topic: https://groups.io/mt/113583366/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [edk2-devel] [PATCH 4/4] RedfishPkg/RedfishConfigHandler: Free handle buffers after LocateHandleBuffer
  2025-06-11  4:03 [edk2-devel] [PATCH 1/4] MdeModulePkg/SpiBus: Free handle buffers after LocateHandleBuffer Dongyan Qian
  2025-06-11  4:03 ` [edk2-devel] [PATCH 2/4] NetworkPkg/HttpUtilitiesDxe: " Dongyan Qian
  2025-06-11  4:03 ` [edk2-devel] [PATCH 3/4] PrmPkg/DxePrmContextBufferLib: " Dongyan Qian
@ 2025-06-11  4:03 ` Dongyan Qian
  2 siblings, 0 replies; 4+ messages in thread
From: Dongyan Qian @ 2025-06-11  4:03 UTC (permalink / raw)
  To: devel

Fix memory leaks by adding missing FreePool calls:
free handle buffers in Stop and initialization routines.

REF: https://uefi.org/sites/default/files/resources/UEFI_Spec_Final_2.11.pdf
Chapter 7.3.15: "Services - Boot Services.LocateHandleBuffer":
It is the caller's responsibility to call the Boot Service.FreePool when
the caller no longer requires the contents of Buffer.

Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
---
 .../RedfishConfigHandler/RedfishConfigHandlerCommon.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c
index bc1ba59835..d0e6a1aca7 100644
--- a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c
+++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c
@@ -189,7 +189,7 @@ RedfishConfigCommonStop (
                   &HandleBuffer
                   );
   if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
-    return Status;
+    goto Exit;
   }
 
   Status = EFI_SUCCESS;
@@ -208,6 +208,11 @@ RedfishConfigCommonStop (
     }
   }
 
+Exit:
+  if (HandleBuffer != NULL) {
+    FreePool (HandleBuffer);
+  }
+
   return Status;
 }
 
@@ -272,4 +277,8 @@ RedfishConfigHandlerInitialization (
                     );
     ASSERT_EFI_ERROR (Status);
   }
+
+  if (HandleBuffer != NULL) {
+    gBS->FreePool (HandleBuffer);
+  }
 }
-- 
2.49.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#121413): https://edk2.groups.io/g/devel/message/121413
Mute This Topic: https://groups.io/mt/113583365/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-11  4:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11  4:03 [edk2-devel] [PATCH 1/4] MdeModulePkg/SpiBus: Free handle buffers after LocateHandleBuffer Dongyan Qian
2025-06-11  4:03 ` [edk2-devel] [PATCH 2/4] NetworkPkg/HttpUtilitiesDxe: " Dongyan Qian
2025-06-11  4:03 ` [edk2-devel] [PATCH 3/4] PrmPkg/DxePrmContextBufferLib: " Dongyan Qian
2025-06-11  4:03 ` [edk2-devel] [PATCH 4/4] RedfishPkg/RedfishConfigHandler: " Dongyan Qian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox