Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/npf - npftest: fix a memleak in a unit test (standa...



details:   https://anonhg.NetBSD.org/src/rev/da5ae034a64b
branches:  trunk
changeset: 844540:da5ae034a64b
user:      rmind <rmind%NetBSD.org@localhost>
date:      Wed Aug 21 21:41:53 2019 +0000

description:
- npftest: fix a memleak in a unit test (standalone path only).
- Minor style fixes.  No functional change.

diffstat:

 usr.sbin/npf/npfctl/npfctl.c                    |   4 ++--
 usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c |   1 +
 usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c |  14 +++++++-------
 3 files changed, 10 insertions(+), 9 deletions(-)

diffs (65 lines):

diff -r a10e120218ff -r da5ae034a64b usr.sbin/npf/npfctl/npfctl.c
--- a/usr.sbin/npf/npfctl/npfctl.c      Wed Aug 21 20:31:23 2019 +0000
+++ b/usr.sbin/npf/npfctl/npfctl.c      Wed Aug 21 21:41:53 2019 +0000
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npfctl.c,v 1.60 2019/07/25 00:48:55 rmind Exp $");
+__RCSID("$NetBSD: npfctl.c,v 1.61 2019/08/21 21:41:53 rmind Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -701,7 +701,7 @@
        if (kernver != NPF_VERSION) {
                errx(EXIT_FAILURE,
                    "incompatible NPF interface version (%d, kernel %d)\n"
-                   "Hint: update %s?", NPF_VERSION, kernver, 
+                   "Hint: update %s?", NPF_VERSION, kernver,
                    kernver > NPF_VERSION ? "userland" : "kernel");
        }
        return fd;
diff -r a10e120218ff -r da5ae034a64b usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c
--- a/usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c   Wed Aug 21 20:31:23 2019 +0000
+++ b/usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c   Wed Aug 21 21:41:53 2019 +0000
@@ -101,6 +101,7 @@
                memcpy(dptr, m->m_data, m->m_len);
                dptr += m->m_len;
        }
+       npfkern_m_freem(*m0);
        *m0 = m1;
        (void)len;
        return true;
diff -r a10e120218ff -r da5ae034a64b usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c
--- a/usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c   Wed Aug 21 20:31:23 2019 +0000
+++ b/usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c   Wed Aug 21 21:41:53 2019 +0000
@@ -190,22 +190,22 @@
 bool
 npf_nbuf_test(bool verbose)
 {
-       struct mbuf *m1, *m2;
+       struct mbuf *m;
        char *bufa, *bufb;
        unsigned n = 10000;
        bool ok;
 
        while (n--) {
-               m1 = mbuf_random_len(MBUF_CHAIN_LEN);
-               bufa = mbuf_getstring(m1);
-               bufb = parse_nbuf_chain(m1);
+               m = mbuf_random_len(MBUF_CHAIN_LEN);
+               bufa = mbuf_getstring(m);
+               bufb = parse_nbuf_chain(m);
                ok = validate_mbuf_data(bufa, bufb);
                CHECK_TRUE(ok);
        }
 
-       m2 = mbuf_bytesize(MBUF_CHAIN_LEN);
-       bufa = mbuf_getstring(m2);
-       bufb = parse_nbuf_chain(m2);
+       m = mbuf_bytesize(MBUF_CHAIN_LEN);
+       bufa = mbuf_getstring(m);
+       bufb = parse_nbuf_chain(m);
        ok = validate_mbuf_data(bufa, bufb);
        CHECK_TRUE(ok);
 



Home | Main Index | Thread Index | Old Index