From d7eec79b7021b8d96bfc327326b84ad7a9edcfb8 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 4 Oct 2022 12:46:39 -0400 Subject: [PATCH] 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); }