Author: oshogbo
Date: Tue Aug 11 18:17:31 2015
New Revision: 286646
URL: https://svnweb.freebsd.org/changeset/base/286646

Log:
  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)

Modified:
  head/sys/contrib/libnv/nvlist.c

Modified: head/sys/contrib/libnv/nvlist.c
==============================================================================
--- head/sys/contrib/libnv/nvlist.c     Tue Aug 11 18:01:10 2015        
(r286645)
+++ head/sys/contrib/libnv/nvlist.c     Tue Aug 11 18:17:31 2015        
(r286646)
@@ -629,10 +629,8 @@ nvlist_xpack(const nvlist_t *nvl, int64_
 
                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_
                        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_
                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_
                        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 *
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to