[edk2-devel] [PATCH v3 1/5] OvmfPkg/GenericQemuLoadImageLib: plug cmdline blob leak on success

Dov Murik dovmurik at linux.ibm.com
Mon Jun 28 10:51:06 UTC 2021

When QemuLoadKernelImage() ends successfully, the command-line blob is
not freed, even though it is not used elsewhere (its content is already
copied to KernelLoadedImage->LoadOptions).  The memory leak bug was
introduced in commit ddd2be6b0026 ("OvmfPkg: provide a generic
implementation of QemuLoadImageLib", 2020-03-05).

Cc: Ard Biesheuvel <ardb+tianocore at kernel.org>
Cc: Jordan Justen <jordan.l.justen at intel.com>
Cc: James Bottomley <jejb at linux.ibm.com>
Cc: Tobin Feldman-Fitzthum <tobin at linux.ibm.com>
Reported-by: Laszlo Ersek <lersek at redhat.com>
Fixes: ddd2be6b0026abcd0f819b3915fc80c3de81dd62
Signed-off-by: Dov Murik <dovmurik at linux.ibm.com>
 OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c
index 114db7e8441f..8a29976ae172 100644
--- a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c
+++ b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c
@@ -193,14 +193,16 @@ QemuLoadKernelImage (
   *ImageHandle = KernelImageHandle;
-  return EFI_SUCCESS;
+  Status = EFI_SUCCESS;
   if (CommandLineSize > 0) {
     FreePool (CommandLine);
-  gBS->UnloadImage (KernelImageHandle);
+  if (EFI_ERROR (Status)) {
+    gBS->UnloadImage (KernelImageHandle);
+  }
   return Status;

Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#77172): https://edk2.groups.io/g/devel/message/77172
Mute This Topic: https://groups.io/mt/83841912/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]

More information about the edk2-devel-archive mailing list