From 266a8c09ec01c6016be641ddb970e240bdac80cc Mon Sep 17 00:00:00 2001 From: InterLinked1 <24227567+InterLinked1@users.noreply.github.com> Date: Fri, 10 Jan 2025 22:05:30 -0500 Subject: [PATCH] pty.c: Close file descriptors in off-nominal branch of PTY master thread. All paths in the PTY master thread close both file descriptors before breaking, except one, which can result in a file descriptor leak of one of the file descriptors when that branch is taken. This resulted in a leak of 1 file descriptor per remote console open at shutdown. While that case is not a meaningful leak, we now always close both descriptors in all branches to prevent this leak from happening. Resolves: #20 --- bbs/pty.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bbs/pty.c b/bbs/pty.c index 2ceb553..9e927e8 100644 --- a/bbs/pty.c +++ b/bbs/pty.c @@ -217,6 +217,10 @@ static void *pty_master_fd(void *varg) } } } else { + /* Something else happened that should effect a disconnect. */ + bbs_debug(10, "Exceptional activity returned from poll: %s/%s\n", poll_revent_name(fds[0].revents), poll_revent_name(fds[1].revents)); + close(fds[1].fd); + close(fds[0].fd); break; } }