summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDov Murik <dovmurik@linux.ibm.com>2021-06-28 10:51:07 +0000
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-06-29 12:33:17 +0000
commit932449710c1669507c87e2b87844c9adf85981d3 (patch)
tree8710f2ef1bf06d330c4c9b8bf763f251fdfc42ca
parent5a2e030f733752a8029bccfa7d28679e103540e0 (diff)
downloadedk2-932449710c1669507c87e2b87844c9adf85981d3.zip
edk2-932449710c1669507c87e2b87844c9adf85981d3.tar.gz
edk2-932449710c1669507c87e2b87844c9adf85981d3.tar.bz2
OvmfPkg/X86QemuLoadImageLib: plug cmdline blob leak on success
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 7c47d89003a6 ("OvmfPkg: implement QEMU loader library for X86 with legacy fallback", 2020-03-05). Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Tobin Feldman-Fitzthum <tobin@linux.ibm.com> Reported-by: Laszlo Ersek <lersek@redhat.com> Fixes: 7c47d89003a6f8f7f6f0ce8ca7d3e87c630d14cc Signed-off-by: Dov Murik <dovmurik@linux.ibm.com> Message-Id: <20210628105110.379951-3-dovmurik@linux.ibm.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Laszlo Ersek <lersek@redhat.com>
-rw-r--r--OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c b/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c
index 1177582..6b1e7e6 100644
--- a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c
+++ b/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c
@@ -446,14 +446,16 @@ QemuLoadKernelImage (
}
*ImageHandle = KernelImageHandle;
- return EFI_SUCCESS;
+ Status = EFI_SUCCESS;
FreeCommandLine:
if (CommandLineSize > 0) {
FreePool (CommandLine);
}
UnloadImage:
- gBS->UnloadImage (KernelImageHandle);
+ if (EFI_ERROR (Status)) {
+ gBS->UnloadImage (KernelImageHandle);
+ }
return Status;
}