git: d7eec79b7021 - main - makefs: Plug a memory leak

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 04 Oct 2022 17:06:16 UTC
The branch main has been updated by markj:

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

commit d7eec79b7021b8d96bfc327326b84ad7a9edcfb8
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-10-04 16:46:39 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-10-04 17:05:54 +0000

    makefs: Plug a memory leak
    
    nvlist_find_string() would return a copy of the found value, but callers
    assumed they would have to make their own copy.  It's simpler to change
    nvlist_find_string() than it is to change callers, so do that.
    
    Reported by:    Coverity
---
 usr.sbin/makefs/zfs/dsl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/makefs/zfs/dsl.c b/usr.sbin/makefs/zfs/dsl.c
index 28560dd4a429..52cb2fa22589 100644
--- a/usr.sbin/makefs/zfs/dsl.c
+++ b/usr.sbin/makefs/zfs/dsl.c
@@ -75,10 +75,8 @@ nvlist_find_string(nvlist_t *nvl, const char *key, char **retp)
 	int error, len;
 
 	error = nvlist_find(nvl, key, DATA_TYPE_STRING, NULL, &str, &len);
-	if (error == 0) {
-		*retp = ecalloc(1, len + 1);
-		memcpy(*retp, str, len);
-	}
+	if (error == 0)
+		*retp = str;
 	return (error);
 }