Skip to content

Commit

Permalink
libnv: fix memory leaks
Browse files Browse the repository at this point in the history
nvpair_create_stringv: free the temporary string; this fix affects
nvlist_add_stringf() and nvlist_add_stringv().

nvpair_remove_nvlist_array (NV_TYPE_NVLIST_ARRAY case): free the chain
of nvpairs (as resetting it prevents nvlist_destroy() from freeing it).
Note: freeing the chain in nvlist_destroy() is not sufficient, because
it would still leak through nvlist_take_nvlist_array().  This affects
all nvlist_*_nvlist_array() use

Submitted by:	Mindaugas Rasiukevicius <[email protected]>
Reported by:	clang/gcc ASAN
MFC after:	2 weeks

(cherry picked from commit b5d787d)
  • Loading branch information
oshogbo committed Jul 6, 2021
1 parent 4b74458 commit f98545c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sys/contrib/libnv/bsd_nvpair.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,16 @@ nvpair_remove_nvlist_array(nvpair_t *nvp)
nvlarray = __DECONST(nvlist_t **,
nvpair_get_nvlist_array(nvp, &count));
for (i = 0; i < count; i++) {
nvlist_set_array_next(nvlarray[i], NULL);
nvlist_set_parent(nvlarray[i], NULL);
nvlist_t *nvl;
nvpair_t *nnvp;

nvl = nvlarray[i];
nnvp = nvlist_get_array_next_nvpair(nvl);
if (nnvp != NULL) {
nvpair_free_structure(nnvp);
}
nvlist_set_array_next(nvl, NULL);
nvlist_set_parent(nvl, NULL);
}
}

Expand Down

0 comments on commit f98545c

Please sign in to comment.