From owner-dev-commits-src-branches@freebsd.org Thu Jun 3 13:40:33 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A1CE8639BE7; Thu, 3 Jun 2021 13:40:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fwn8d4Dw9z3KcL; Thu, 3 Jun 2021 13:40:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6C0AD2960; Thu, 3 Jun 2021 13:40:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 153DeX3P038481; Thu, 3 Jun 2021 13:40:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 153DeX3c038477; Thu, 3 Jun 2021 13:40:33 GMT (envelope-from git) Date: Thu, 3 Jun 2021 13:40:33 GMT Message-Id: <202106031340.153DeX3c038477@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 38da14043dcc - stable/13 - libpfctl: fix memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 38da14043dcc960e0316846d2042fea1e0543b07 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2021 13:40:33 -0000 The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=38da14043dcc960e0316846d2042fea1e0543b07 commit 38da14043dcc960e0316846d2042fea1e0543b07 Author: Kristof Provost AuthorDate: 2021-05-27 09:28:36 +0000 Commit: Kristof Provost CommitDate: 2021-06-03 13:38:25 +0000 libpfctl: fix memory leak When we create an nvlist and insert it into another nvlist we must remember to destroy it. The nvlist_add_nvlist() function makes a copy, just like nvlist_add_string() makes a copy of the string. See also 4483fb47735c29408c72045469c9c4b3e549668b Reviewed by: scottl MFC after: 3 days Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D30492 (cherry picked from commit 6dbb729d35d59cc8bc8451bd56f220f9c35a43f3) --- lib/libpfctl/libpfctl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c index e207a55a8673..ebc026800a1b 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -130,6 +130,7 @@ pfctl_nv_add_addr(nvlist_t *nvparent, const char *name, nvlist_add_binary(nvl, "addr", addr, sizeof(*addr)); nvlist_add_nvlist(nvparent, name, nvl); + nvlist_destroy(nvl); } static void @@ -159,6 +160,7 @@ pfctl_nv_add_addr_wrap(nvlist_t *nvparent, const char *name, pfctl_nv_add_addr(nvl, "mask", &addr->v.a.mask); nvlist_add_nvlist(nvparent, name, nvl); + nvlist_destroy(nvl); } static void @@ -192,6 +194,7 @@ pfctl_nv_add_rule_addr(nvlist_t *nvparent, const char *name, nvlist_add_number(nvl, "port_op", addr->port_op); nvlist_add_nvlist(nvparent, name, nvl); + nvlist_destroy(nvl); } static void @@ -214,6 +217,7 @@ pfctl_nv_add_mape(nvlist_t *nvparent, const char *name, nvlist_add_number(nvl, "psidlen", mape->psidlen); nvlist_add_number(nvl, "psid", mape->psid); nvlist_add_nvlist(nvparent, name, nvl); + nvlist_destroy(nvl); } static void @@ -234,6 +238,7 @@ pfctl_nv_add_pool(nvlist_t *nvparent, const char *name, pfctl_nv_add_mape(nvl, "mape", &pool->mape); nvlist_add_nvlist(nvparent, name, nvl); + nvlist_destroy(nvl); } static void @@ -277,6 +282,7 @@ pfctl_nv_add_uid(nvlist_t *nvparent, const char *name, nvlist_add_number(nvl, "op", uid->op); nvlist_add_nvlist(nvparent, name, nvl); + nvlist_destroy(nvl); } static void @@ -296,6 +302,7 @@ pfctl_nv_add_divert(nvlist_t *nvparent, const char *name, nvlist_add_number(nvl, "port", r->divert.port); nvlist_add_nvlist(nvparent, name, nvl); + nvlist_destroy(nvl); } static void @@ -511,6 +518,7 @@ pfctl_add_rule(int dev, const struct pfctl_rule *r, const char *anchor, pfctl_nv_add_divert(nvlr, "divert", r); nvlist_add_nvlist(nvl, "rule", nvlr); + nvlist_destroy(nvlr); /* Now do the call. */ nv.data = nvlist_pack(nvl, &nv.len); @@ -625,6 +633,7 @@ pfctl_nv_add_state_cmp(nvlist_t *nvl, const char *name, nvlist_add_number(nv, "direction", cmp->direction); nvlist_add_nvlist(nvl, name, nv); + nvlist_destroy(nv); } static void