git: 88069992b210 - stable/14 - bhyve: avoid resource leak in error path

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Thu, 01 Aug 2024 17:35:57 UTC
The branch stable/14 has been updated by emaste:

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

commit 88069992b210f659327024babb80589d86a2c119
Author:     Pierre Pronchery <pierre@freebsdfoundation.org>
AuthorDate: 2024-05-16 16:55:54 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-08-01 17:34:50 +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
    
    (cherry picked from commit e9806d21282d3d5486b99b5c7062b490b00d8323)
---
 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);