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


Dov Murik
 

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@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: James Bottomley <jejb@...>
Cc: Tobin Feldman-Fitzthum <tobin@...>
Reported-by: Laszlo Ersek <lersek@...>
Fixes: ddd2be6b0026abcd0f819b3915fc80c3de81dd62
Signed-off-by: Dov Murik <dovmurik@...>
---
OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c | 6 ++++=
--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLi=
b.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 (
}=0D
=0D
*ImageHandle =3D KernelImageHandle;=0D
- return EFI_SUCCESS;=0D
+ Status =3D EFI_SUCCESS;=0D
=0D
FreeCommandLine:=0D
if (CommandLineSize > 0) {=0D
FreePool (CommandLine);=0D
}=0D
UnloadImage:=0D
- gBS->UnloadImage (KernelImageHandle);=0D
+ if (EFI_ERROR (Status)) {=0D
+ gBS->UnloadImage (KernelImageHandle);=0D
+ }=0D
=0D
return Status;=0D
}=0D
--=20
2.25.1

Join {devel@edk2.groups.io to automatically receive all group messages.