From owner-svn-src-all@freebsd.org Tue Aug 11 18:17:32 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 60CEB99FCBF; Tue, 11 Aug 2015 18:17:32 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 35F02EF1; Tue, 11 Aug 2015 18:17:32 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7BIHWEC064788; Tue, 11 Aug 2015 18:17:32 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7BIHW0Z064787; Tue, 11 Aug 2015 18:17:32 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201508111817.t7BIHW0Z064787@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Tue, 11 Aug 2015 18:17:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286646 - head/sys/contrib/libnv X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Aug 2015 18:17:32 -0000 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 *