git: e225983737b4 - main - makefs: Fix memory leaks in dsl_dir_finalize_props()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 11 Aug 2022 14:20:18 UTC
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e225983737b42c7dd732ffed2de194e0bd2a3378 commit e225983737b42c7dd732ffed2de194e0bd2a3378 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2022-08-11 14:18:06 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-08-11 14:18:06 +0000 makefs: Fix memory leaks in dsl_dir_finalize_props() nvstring_get() returns a copy of the string, not a pointer into the nvlist's internal buffer. Reported by: Coverity Fixes: 240afd8c1fcc ("makefs: Add ZFS support") Sponsored by: The FreeBSD Foundation --- usr.sbin/makefs/zfs/dsl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/usr.sbin/makefs/zfs/dsl.c b/usr.sbin/makefs/zfs/dsl.c index 5f473e557c02..1d20f5f3891a 100644 --- a/usr.sbin/makefs/zfs/dsl.c +++ b/usr.sbin/makefs/zfs/dsl.c @@ -443,7 +443,7 @@ dsl_dir_finalize_props(zfs_dsl_dir_t *dir) (nvh = nvlist_next_nvpair(dir->propsnv, nvh)) != NULL;) { nv_string_t *nvname; nv_pair_data_t *nvdata; - const char *name; + char *name; nvname = (nv_string_t *)(nvh + 1); nvdata = (nv_pair_data_t *)(&nvname->nv_data[0] + @@ -460,15 +460,18 @@ dsl_dir_finalize_props(zfs_dsl_dir_t *dir) } case DATA_TYPE_STRING: { nv_string_t *nvstr; + char *val; nvstr = (nv_string_t *)&nvdata->nv_data[0]; - zap_add_string(dir->propszap, name, - nvstring_get(nvstr)); + val = nvstring_get(nvstr); + zap_add_string(dir->propszap, name, val); + free(val); break; } default: assert(0); } + free(name); } }