git: 37eb7030a0fb - stable/14 - bhyve: Fix a leak that happens when we fail to load a hostfwd rule

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 26 Dec 2023 02:08:25 UTC
The branch stable/14 has been updated by markj:

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

commit 37eb7030a0fb6543e402799fff2be31645e1dbac
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-12-01 14:46:31 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-12-25 16:57:14 +0000

    bhyve: Fix a leak that happens when we fail to load a hostfwd rule
    
    Reported by:    Coverity
    Fixes:          c5359e2af5ab ("bhyve: Add a slirp network backend")
    
    (cherry picked from commit 1cc96501e58057fba62cdebd514cdc9197d6e97c)
---
 usr.sbin/bhyve/net_backend_slirp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/usr.sbin/bhyve/net_backend_slirp.c b/usr.sbin/bhyve/net_backend_slirp.c
index 1c414f87084c..1d6ed45b90f2 100644
--- a/usr.sbin/bhyve/net_backend_slirp.c
+++ b/usr.sbin/bhyve/net_backend_slirp.c
@@ -502,8 +502,10 @@ _slirp_init(struct net_backend *be, const char *devname __unused,
 			goto err;
 		while ((rule = strsep(&rules, ";")) != NULL) {
 			error = config_one_hostfwd(priv, rule);
-			if (error != 0)
+			if (error != 0) {
+				free(tofree);
 				goto err;
+			}
 		}
 		free(tofree);
 	}