From 8383006f0fa683fa0dbb3dec155e4a41a9af4bc1 Mon Sep 17 00:00:00 2001 From: wrstuden Date: Sat, 6 Mar 2004 00:38:29 +0000 Subject: [PATCH] Handle the case of fifo_close() getting called from vclean(). In that case, we tear down the node-specific storage as if there were no more open users. As vclean() will VT_NON the vnode before anyone else will get access to the vnode, this is our last chance. Fixes memory leak in revoke(2) path noticed by tedu at openbsd dot org. --- sys/miscfs/fifofs/fifo_vnops.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sys/miscfs/fifofs/fifo_vnops.c b/sys/miscfs/fifofs/fifo_vnops.c index b484f6bc9b87..ffaede438deb 100644 --- a/sys/miscfs/fifofs/fifo_vnops.c +++ b/sys/miscfs/fifofs/fifo_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: fifo_vnops.c,v 1.45 2003/11/29 10:02:42 matt Exp $ */ +/* $NetBSD: fifo_vnops.c,v 1.46 2004/03/06 00:38:29 wrstuden Exp $ */ /* * Copyright (c) 1990, 1993, 1995 @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.45 2003/11/29 10:02:42 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.46 2004/03/06 00:38:29 wrstuden Exp $"); #include #include @@ -440,7 +440,12 @@ fifo_close(void *v) if (--fip->fi_writers == 0) socantrcvmore(fip->fi_readsock); } - if (--fip->fi_opencount == 0) { + /* + * shut down if either last close, or if close called from + * vclean() + */ + if ((--fip->fi_opencount == 0) + || ((ap->a_fflag & (FREAD | FWRITE | FNONBLOCK)) == FNONBLOCK)) { (void) soclose(fip->fi_readsock); (void) soclose(fip->fi_writesock); FREE(fip, M_VNODE);