Keep track of the allocated size and use it later :) ok?
Index: kern/vfs_subr.c =================================================================== RCS file: /cvs/src/sys/kern/vfs_subr.c,v retrieving revision 1.282 diff -u -p -r1.282 vfs_subr.c --- kern/vfs_subr.c 29 Sep 2018 04:29:48 -0000 1.282 +++ kern/vfs_subr.c 18 Nov 2018 16:05:25 -0000 @@ -1424,6 +1424,7 @@ vfs_hang_addrlist(struct mount *mp, stru return (EINVAL); nplen = sizeof(struct netcred) + argp->ex_addrlen + argp->ex_masklen; np = (struct netcred *)malloc(nplen, M_NETADDR, M_WAITOK|M_ZERO); + np->netc_len = nplen; saddr = (struct sockaddr *)(np + 1); error = copyin(argp->ex_addr, saddr, argp->ex_addrlen); if (error) @@ -1466,7 +1467,7 @@ finish: np->netc_exflags = argp->ex_flags; return (0); out: - free(np, M_NETADDR, nplen); + free(np, M_NETADDR, np->netc_len); return (error); } @@ -1474,9 +1475,10 @@ int vfs_free_netcred(struct radix_node *rn, void *w, u_int id) { struct radix_node_head *rnh = (struct radix_node_head *)w; + struct netcred * np = (struct netcred *)rn; rn_delete(rn->rn_key, rn->rn_mask, rnh, NULL); - free(rn, M_NETADDR, 0); + free(np, M_NETADDR, np->netc_len); return (0); } @@ -1490,7 +1492,7 @@ vfs_free_addrlist(struct netexport *nep) if ((rnh = nep->ne_rtable_inet) != NULL) { rn_walktree(rnh, vfs_free_netcred, rnh); - free(rnh, M_RTABLE, 0); + free(rnh, M_RTABLE, sizeof(*rnh)); nep->ne_rtable_inet = NULL; } } Index: sys/mount.h =================================================================== RCS file: /cvs/src/sys/sys/mount.h,v retrieving revision 1.142 diff -u -p -r1.142 mount.h --- sys/mount.h 29 Sep 2018 04:29:48 -0000 1.142 +++ sys/mount.h 18 Nov 2018 16:00:22 -0000 @@ -552,6 +552,7 @@ struct vfsops { struct netcred { struct radix_node netc_rnodes[2]; int netc_exflags; + int netc_len; /* size of the allocation */ struct ucred netc_anon; };