From owner-svn-src-all@FreeBSD.ORG Tue Nov 24 14:40:50 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60C44106566B; Tue, 24 Nov 2009 14:40:50 +0000 (UTC) (envelope-from attilio@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4EF488FC0C; Tue, 24 Nov 2009 14:40:50 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nAOEeoHr019789; Tue, 24 Nov 2009 14:40:50 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nAOEeoOU019787; Tue, 24 Nov 2009 14:40:50 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <200911241440.nAOEeoOU019787@svn.freebsd.org> From: Attilio Rao Date: Tue, 24 Nov 2009 14:40:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r199750 - stable/6/sys/fs/fifofs X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Nov 2009 14:40:50 -0000 Author: attilio Date: Tue Nov 24 14:40:50 2009 New Revision: 199750 URL: http://svn.freebsd.org/changeset/base/199750 Log: MFC 199007: Fix a memory leak. Modified: stable/6/sys/fs/fifofs/fifo_vnops.c Directory Properties: stable/6/sys/ (props changed) stable/6/sys/conf/ (props changed) stable/6/sys/contrib/pf/ (props changed) stable/6/sys/dev/cxgb/ (props changed) Modified: stable/6/sys/fs/fifofs/fifo_vnops.c ============================================================================== --- stable/6/sys/fs/fifofs/fifo_vnops.c Tue Nov 24 14:06:15 2009 (r199749) +++ stable/6/sys/fs/fifofs/fifo_vnops.c Tue Nov 24 14:40:50 2009 (r199750) @@ -76,6 +76,9 @@ struct fileops fifo_ops_f = { /* * This structure is associated with the FIFO vnode and stores * the state associated with the FIFO. + * Notes about locking: + * - fi_readsock and fi_writesock are invariant since init time. + * - fi_readers and fi_writers are vnode lock protected. */ struct fifoinfo { struct socket *fi_readsock; @@ -212,14 +215,9 @@ fail1: } /* - * General access to fi_readers and fi_writers is protected using - * the vnode lock. - * - * Protect the increment of fi_readers and fi_writers and the - * associated calls to wakeup() with the fifo mutex in addition - * to the vnode lock. This allows the vnode lock to be dropped - * for the msleep() calls below, and using the fifo mutex with - * msleep() prevents the wakeup from being missed. + * Use the fifo_mtx lock here, in addition to the vnode lock, + * in order to allow vnode lock dropping before msleep() calls + * and still avoiding missed wakeups. */ mtx_lock(&fifo_mtx); if (ap->a_mode & FREAD) { @@ -237,6 +235,8 @@ fail1: if (ap->a_mode & FWRITE) { if ((ap->a_mode & O_NONBLOCK) && fip->fi_readers == 0) { mtx_unlock(&fifo_mtx); + if (fip->fi_writers == 0) + fifo_cleanup(vp); return (ENXIO); } fip->fi_writers++;