summaryrefslogtreecommitdiffstats
path: root/sys/contrib
diff options
context:
space:
mode:
authoroshogbo <oshogbo@FreeBSD.org>2015-08-11 18:17:31 +0000
committeroshogbo <oshogbo@FreeBSD.org>2015-08-11 18:17:31 +0000
commitb7ba9a6094844fd8a0516a925817d44b2d3d3e32 (patch)
tree61bc3d4400d40202d42fe21a9c385ba30fbc8d4f /sys/contrib
parentcb6dbe5ae738e157194b66d8beba27a81dba8679 (diff)
downloadFreeBSD-src-b7ba9a6094844fd8a0516a925817d44b2d3d3e32.zip
FreeBSD-src-b7ba9a6094844fd8a0516a925817d44b2d3d3e32.tar.gz
If any function fail (the ptr variable will be equal to NULL), we shouldn't
return buffer. Instead we should free it and return NULL. Approved by: pjd (mentor)
Diffstat (limited to 'sys/contrib')
-rw-r--r--sys/contrib/libnv/nvlist.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/sys/contrib/libnv/nvlist.c b/sys/contrib/libnv/nvlist.c
index c6bb61e..edcd074 100644
--- a/sys/contrib/libnv/nvlist.c
+++ b/sys/contrib/libnv/nvlist.c
@@ -629,10 +629,8 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
nvpair_init_datasize(nvp);
ptr = nvpair_pack_header(nvp, ptr, &left);
- if (ptr == NULL) {
- nv_free(buf);
- return (NULL);
- }
+ if (ptr == NULL)
+ goto fail;
switch (nvpair_type(nvp)) {
case NV_TYPE_NULL:
ptr = nvpair_pack_null(nvp, ptr, &left);
@@ -650,7 +648,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
tmpnvl = nvpair_get_nvlist(nvp);
ptr = nvlist_pack_header(tmpnvl, ptr, &left);
if (ptr == NULL)
- goto out;
+ goto fail;
tmpnvp = nvlist_first_nvpair(tmpnvl);
if (tmpnvp != NULL) {
nvl = tmpnvl;
@@ -670,10 +668,8 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
default:
PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
}
- if (ptr == NULL) {
- nv_free(buf);
- return (NULL);
- }
+ if (ptr == NULL)
+ goto fail;
while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
cookie = NULL;
nvl = nvlist_get_parent(nvl, &cookie);
@@ -682,7 +678,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
nvp = cookie;
ptr = nvpair_pack_nvlist_up(ptr, &left);
if (ptr == NULL)
- goto out;
+ goto fail;
}
}
@@ -690,6 +686,9 @@ out:
if (sizep != NULL)
*sizep = size;
return (buf);
+fail:
+ nv_free(buf);
+ return (NULL);
}
void *
OpenPOWER on IntegriCloud