From owner-svn-src-head@freebsd.org Wed Dec 2 02:47:15 2015 Return-Path: Delivered-To: svn-src-head@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 E5B9EA3EBFD; Wed, 2 Dec 2015 02:47:14 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 C22C6161D; Wed, 2 Dec 2015 02:47:14 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tB22lDkU093595; Wed, 2 Dec 2015 02:47:13 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tB22lDYd093592; Wed, 2 Dec 2015 02:47:13 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201512020247.tB22lDYd093592@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Wed, 2 Dec 2015 02:47:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291638 - head/sys/fs/nfs X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Dec 2015 02:47:15 -0000 Author: rmacklem Date: Wed Dec 2 02:47:13 2015 New Revision: 291638 URL: https://svnweb.freebsd.org/changeset/base/291638 Log: Fix the memory leak that occurs when the nfscommon.ko module is unloaded. This leak was introduced by r291527. Since the nfscommon.ko module is rarely unloaded, this leak would not have been much of an issue. MFC after: 2 weeks Modified: head/sys/fs/nfs/nfs_commonport.c head/sys/fs/nfs/nfs_commonsubs.c head/sys/fs/nfs/nfs_var.h Modified: head/sys/fs/nfs/nfs_commonport.c ============================================================================== --- head/sys/fs/nfs/nfs_commonport.c Wed Dec 2 02:11:38 2015 (r291637) +++ head/sys/fs/nfs/nfs_commonport.c Wed Dec 2 02:47:13 2015 (r291638) @@ -623,6 +623,8 @@ nfscommon_modevent(module_t mod, int typ nfsd_call_nfscommon = NULL; callout_drain(&newnfsd_callout); + /* Clean out the name<-->id cache. */ + nfsrv_cleanusergroup(); /* and get rid of the mutexes */ mtx_destroy(&nfs_nameid_mutex); mtx_destroy(&newnfsd_mtx); Modified: head/sys/fs/nfs/nfs_commonsubs.c ============================================================================== --- head/sys/fs/nfs/nfs_commonsubs.c Wed Dec 2 02:11:38 2015 (r291637) +++ head/sys/fs/nfs/nfs_commonsubs.c Wed Dec 2 02:47:13 2015 (r291638) @@ -3546,6 +3546,55 @@ nfsrv_removeuser(struct nfsusrgrp *usrp, } /* + * Free up all the allocations related to the name<-->id cache. + * This function should only be called when the nfsuserd daemon isn't + * running, since it doesn't do any locking. + * This function is meant to be used when the nfscommon module is unloaded. + */ +APPLESTATIC void +nfsrv_cleanusergroup(void) +{ + struct nfsrv_lughash *hp, *hp2; + struct nfsusrgrp *nusrp, *usrp; + int i; + + if (nfsuserhash == NULL) + return; + + for (i = 0; i < nfsrv_lughashsize; i++) { + hp = &nfsuserhash[i]; + TAILQ_FOREACH_SAFE(usrp, &hp->lughead, lug_numhash, nusrp) { + TAILQ_REMOVE(&hp->lughead, usrp, lug_numhash); + hp2 = NFSUSERNAMEHASH(usrp->lug_name, + usrp->lug_namelen); + TAILQ_REMOVE(&hp2->lughead, usrp, lug_namehash); + if (usrp->lug_cred != NULL) + crfree(usrp->lug_cred); + free(usrp, M_NFSUSERGROUP); + } + hp = &nfsgrouphash[i]; + TAILQ_FOREACH_SAFE(usrp, &hp->lughead, lug_numhash, nusrp) { + TAILQ_REMOVE(&hp->lughead, usrp, lug_numhash); + hp2 = NFSGROUPNAMEHASH(usrp->lug_name, + usrp->lug_namelen); + TAILQ_REMOVE(&hp2->lughead, usrp, lug_namehash); + if (usrp->lug_cred != NULL) + crfree(usrp->lug_cred); + free(usrp, M_NFSUSERGROUP); + } + mtx_destroy(&nfsuserhash[i].mtx); + mtx_destroy(&nfsusernamehash[i].mtx); + mtx_destroy(&nfsgroupnamehash[i].mtx); + mtx_destroy(&nfsgrouphash[i].mtx); + } + free(nfsuserhash, M_NFSUSERGROUP); + free(nfsusernamehash, M_NFSUSERGROUP); + free(nfsgrouphash, M_NFSUSERGROUP); + free(nfsgroupnamehash, M_NFSUSERGROUP); + free(nfsrv_dnsname, M_NFSSTRING); +} + +/* * This function scans a byte string and checks for UTF-8 compliance. * It returns 0 if it conforms and NFSERR_INVAL if not. */ Modified: head/sys/fs/nfs/nfs_var.h ============================================================================== --- head/sys/fs/nfs/nfs_var.h Wed Dec 2 02:11:38 2015 (r291637) +++ head/sys/fs/nfs/nfs_var.h Wed Dec 2 02:47:13 2015 (r291638) @@ -283,6 +283,7 @@ void nfsv4_getref(struct nfsv4lock *, in int nfsv4_getref_nonblock(struct nfsv4lock *); int nfsv4_testlock(struct nfsv4lock *); int nfsrv_mtostr(struct nfsrv_descript *, char *, int); +void nfsrv_cleanusergroup(void); int nfsrv_checkutf8(u_int8_t *, int); int newnfs_sndlock(int *); void newnfs_sndunlock(int *);