git: e9806d21282d - main - bhyve: avoid resource leak in error path

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Fri, 17 May 2024 16:26:58 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=e9806d21282d3d5486b99b5c7062b490b00d8323

commit e9806d21282d3d5486b99b5c7062b490b00d8323
Author:     Pierre Pronchery <pierre@freebsdfoundation.org>
AuthorDate: 2024-05-16 16:55:54 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-05-17 16:26:27 +0000

    bhyve: avoid resource leak in error path
    
    In e820_finalize(), the e820_fwcfg_item variable, containing the
    etc/e820 file (for the e820 table from the BIOS) is not free()'d when it
    could not be added to the QEMU firmware configuration device (fw_cfg).
    
    Reported by:    Coverity Scan
    CID:            1522761
    Reviewed by:    corvink, jhb
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D45223
---
 usr.sbin/bhyve/amd64/e820.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/usr.sbin/bhyve/amd64/e820.c b/usr.sbin/bhyve/amd64/e820.c
index 456ce0330b50..9d95ec8ce688 100644
--- a/usr.sbin/bhyve/amd64/e820.c
+++ b/usr.sbin/bhyve/amd64/e820.c
@@ -483,6 +483,8 @@ e820_finalize(void)
 	    e820_fwcfg_item->size, e820_fwcfg_item->data);
 	if (error != 0) {
 		warnx("could not add qemu fwcfg etc/e820");
+		free(e820_fwcfg_item->data);
+		free(e820_fwcfg_item);
 		return (error);
 	}
 	free(e820_fwcfg_item);