[PATCH] hw/uefi/ovmf-log: Fix memory leak in hmp_info_firmware_log

zhaoguohan_salmon@163.com posted 1 patch 3 weeks, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251023063106.9834-1-zhaoguohan._5Fsalmon@163.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>
hw/uefi/ovmf-log.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] hw/uefi/ovmf-log: Fix memory leak in hmp_info_firmware_log
Posted by zhaoguohan_salmon@163.com 3 weeks, 1 day ago
From: GuoHan Zhao <zhaoguohan@kylinos.cn>

The FirmwareLog object returned by qmp_query_firmware_log() was
not being freed, causing a memory leak.

Use g_autoptr to ensure the object is automatically freed when
it goes out of scope.

Fixes: c8aa8120313f ("hw/uefi: add 'info firmware-log' hmp monitor command.")
Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
---
 hw/uefi/ovmf-log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/uefi/ovmf-log.c b/hw/uefi/ovmf-log.c
index 98ebb0209491..850ef21f8859 100644
--- a/hw/uefi/ovmf-log.c
+++ b/hw/uefi/ovmf-log.c
@@ -261,7 +261,7 @@ void hmp_info_firmware_log(Monitor *mon, const QDict *qdict)
     g_autofree gchar *log_esc = NULL;
     g_autofree guchar *log_out = NULL;
     Error *err = NULL;
-    FirmwareLog *log;
+    g_autoptr(FirmwareLog) log = NULL;
     gsize log_len;
     int64_t maxsize;
 
-- 
2.43.0
Re: [PATCH] hw/uefi/ovmf-log: Fix memory leak in hmp_info_firmware_log
Posted by Philippe Mathieu-Daudé 2 weeks, 3 days ago
On 23/10/25 08:31, zhaoguohan_salmon@163.com wrote:
> From: GuoHan Zhao <zhaoguohan@kylinos.cn>
> 
> The FirmwareLog object returned by qmp_query_firmware_log() was
> not being freed, causing a memory leak.
> 
> Use g_autoptr to ensure the object is automatically freed when
> it goes out of scope.
> 
> Fixes: c8aa8120313f ("hw/uefi: add 'info firmware-log' hmp monitor command.")
> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
> ---
>   hw/uefi/ovmf-log.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Already merged as commit b6478122f059274b19805e14d12f76d2c0272ad4.
Re: [PATCH] hw/uefi/ovmf-log: Fix memory leak in hmp_info_firmware_log
Posted by Philippe Mathieu-Daudé 3 weeks, 1 day ago
On 23/10/25 08:31, zhaoguohan_salmon@163.com wrote:
> From: GuoHan Zhao <zhaoguohan@kylinos.cn>
> 
> The FirmwareLog object returned by qmp_query_firmware_log() was
> not being freed, causing a memory leak.
> 
> Use g_autoptr to ensure the object is automatically freed when
> it goes out of scope.
> 
> Fixes: c8aa8120313f ("hw/uefi: add 'info firmware-log' hmp monitor command.")
> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
> ---
>   hw/uefi/ovmf-log.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>