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:		240afd8c1f ("makefs: Add ZFS support")
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Mark Johnston 2022-08-11 10:18:06 -04:00
parent 69077c81e5
commit e225983737

View File

@ -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);
}
}