git: 62bed9d49e41 - stable/13 - bhyve: plug memory leak in topology_parse()

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 26 Jan 2023 19:25:49 UTC
The branch stable/13 has been updated by jhb:

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

commit 62bed9d49e418a48ca9bc36f5f7bc513c547c92f
Author:     Andy Fiddaman <andy@omniosce.org>
AuthorDate: 2022-02-24 17:36:41 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-01-26 19:21:46 +0000

    bhyve: plug memory leak in topology_parse()
    
    Reviewed by:    jhb, rew
    Differential Revision:  https://reviews.freebsd.org/D34301
    
    (cherry picked from commit ad3da82996ffe8a7959fda4a84374b1907ebb116)
---
 usr.sbin/bhyve/bhyverun.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
index 4c2c07b934a7..70dd52c9b2b4 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -271,7 +271,7 @@ usage(int code)
 static int
 topology_parse(const char *opt)
 {
-	char *cp, *str;
+	char *cp, *str, *tofree;
 
 	if (*opt == '\0') {
 		set_config_value("sockets", "1");
@@ -281,7 +281,7 @@ topology_parse(const char *opt)
 		return (0);
 	}
 
-	str = strdup(opt);
+	tofree = str = strdup(opt);
 	if (str == NULL)
 		errx(4, "Failed to allocate memory");
 
@@ -303,11 +303,11 @@ topology_parse(const char *opt)
 		else
 			set_config_value("cpus", cp);
 	}
-	free(str);
+	free(tofree);
 	return (0);
 
 out:
-	free(str);
+	free(tofree);
 	return (-1);
 }