From b754ab83bc91b3be115ec4a1e70651817c669eae Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Thu, 15 Apr 2010 08:17:28 +0000 Subject: [PATCH] MFC r206395: Do not leak master pty or ptmx vnode. --- sys/kern/tty_pts.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/kern/tty_pts.c b/sys/kern/tty_pts.c index e1883d68082..363bdebade0 100644 --- a/sys/kern/tty_pts.c +++ b/sys/kern/tty_pts.c @@ -589,6 +589,15 @@ ptsdev_close(struct file *fp, struct thread *td) tty_lock(tp); tty_rel_gone(tp); + /* + * Open of /dev/ptmx or /dev/ptyXX changes the type of file + * from DTYPE_VNODE to DTYPE_PTS. vn_open() increases vnode + * use count, we need to decrement it, and possibly do other + * required cleanup. + */ + if (fp->f_vnode != NULL) + return (vnops.fo_close(fp, td)); + return (0); }