public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Dongyan Qian" <qiandongyan@loongson.cn>
To: devel@edk2.groups.io
Subject: [edk2-devel] [PATCH 3/4] PrmPkg/DxePrmContextBufferLib: Free handle buffers after LocateHandleBuffer
Date: Wed, 11 Jun 2025 12:03:05 +0800	[thread overview]
Message-ID: <20250611040306.199659-3-qiandongyan@loongson.cn> (raw)
In-Reply-To: <20250611040306.199659-1-qiandongyan@loongson.cn>

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]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2025-06-11  4:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-06-11  4:03 ` [edk2-devel] [PATCH 4/4] RedfishPkg/RedfishConfigHandler: " Dongyan Qian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250611040306.199659-3-qiandongyan@loongson.cn \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox