From 8544d501666caded49206a190636657b9e0f4a09 Mon Sep 17 00:00:00 2001 From: jhb Date: Fri, 9 Dec 2011 17:49:34 +0000 Subject: [PATCH 07/65] Explicitly use curthread while manipulating td_fpop during last close of a devfs file descriptor in devfs_close_f(). The passed in td argument may be NULL if the close was invoked by garbage collection of open file descriptors in pending control messages in the socket buffer of a UNIX domain socket after it was closed. PR: kern/151758 Submitted by: Andrey Shidakov andrey shidakov ru Submitted by: Ruben van Staveren ruben verweg com Reviewed by: kib MFC after: 2 weeks git-svn-id: http://svn.freebsd.org/base/head@228361 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f (cherry picked from commit 5f3285187f94a67f7f46fabc7c9e1f6377f50ea3) Signed-off-by: Xin Li --- sys/fs/devfs/devfs_vnops.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index 22908b9..408c981 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -602,10 +602,14 @@ devfs_close_f(struct file *fp, struct thread *td) int error; struct file *fpop; - fpop = td->td_fpop; - td->td_fpop = fp; + /* + * NB: td may be NULL if this descriptor is closed due to + * garbage collection from a closed UNIX domain socket. + */ + fpop = curthread->td_fpop; + curthread->td_fpop = fp; error = vnops.fo_close(fp, td); - td->td_fpop = fpop; + curthread->td_fpop = fpop; /* * The f_cdevpriv cannot be assigned non-NULL value while we -- 1.7.8.3