From 3ab1dd5cc7279844757069217904a914e5907658 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Fri, 10 Feb 2023 11:27:15 +0100 Subject: [PATCH] ttynvt: Avoid potential "net read error" in _read_net() when closing ttynvt_release() may be called when the poll thread is blocked in a read(FD_NET) (maybe also read(FD_MASTER) - not sure). So ttynvt_release() sets rel_pending before closing the fd, but too late as the read() will return an error when the fd is closed, and before the thread is cancelled. Now we cancel/join the thread before closing the file descriptor(s). --- src/ttynvt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ttynvt.c b/src/ttynvt.c index 9e567eb..d427cc3 100644 --- a/src/ttynvt.c +++ b/src/ttynvt.c @@ -141,15 +141,16 @@ static void ttynvt_release(fuse_req_t req, struct fuse_file_info *info) DBG("%s\n", __func__); tty->rel_pending = 1; - _fd_close(tty->fds[FD_NET].fd); - _fd_close(tty->fds[FD_MASTER].fd); - _fd_close(tty->fds[FD_SLAVE].fd); pthread_cancel(tty->ptid_poll); pthread_join(tty->ptid_poll, NULL); pthread_mutex_destroy(&tty->tty_lock); pthread_mutex_destroy(&tty->poll_lock); + _fd_close(tty->fds[FD_NET].fd); + _fd_close(tty->fds[FD_MASTER].fd); + _fd_close(tty->fds[FD_SLAVE].fd); + if (tty->ph) fuse_pollhandle_destroy(tty->ph);