aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2021-05-27 09:28:36 +0000
committerKristof Provost <kp@FreeBSD.org>2021-06-03 13:38:25 +0000
commit38da14043dcc960e0316846d2042fea1e0543b07 (patch)
tree04a939ae4f44369bf1c6b6aa81f72aa950528aec
parentfcf938e093963bd0a0d92e55c964cfb0b2ce3459 (diff)
downloadsrc-38da14043dcc960e0316846d2042fea1e0543b07.tar.gz
src-38da14043dcc960e0316846d2042fea1e0543b07.zip
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)
-rw-r--r--lib/libpfctl/libpfctl.c9
1 files changed, 9 insertions, 0 deletions
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