From 5c7d7aae68f40bc49fa93ba6ea8bc28f87d3e436 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 29 Apr 2019 06:57:36 -0600 Subject: [PATCH] rktio: fix fd leak in filesystem-change-evt with kqueue Affects Mac OS and BSDs. --- racket/src/rktio/rktio_fs_change.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/racket/src/rktio/rktio_fs_change.c b/racket/src/rktio/rktio_fs_change.c index c19ff1d045..9a8ede8633 100644 --- a/racket/src/rktio/rktio_fs_change.c +++ b/racket/src/rktio/rktio_fs_change.c @@ -3,6 +3,7 @@ #include #include #include +#include #if defined(HAVE_KQUEUE_SYSCALL) # include #endif @@ -169,17 +170,19 @@ static void fs_change_release(rktio_t *rktio, rktio_fs_change_t *fc) # elif defined(HAVE_INOTIFY_SYSCALL) do_inotify_remove(rktio, fc->fd); # elif defined(HAVE_KQUEUE_SYSCALL) - if (rktio_ltps_handle_get_data(rktio, fc->lth)) { - /* Not zeroed, so never signaled. Change the auto behavior - to free the handle, and deregsiter the file descriptor. */ + { rktio_fd_t *rfd; - rktio_ltps_handle_set_auto(rktio, fc->lth, RKTIO_LTPS_HANDLE_FREE); rfd = rktio_system_fd(rktio, fc->fd, 0); - (void)rktio_ltps_add(rktio, fc->lt, rfd, RKTIO_LTPS_REMOVE_VNODE); + if (rktio_ltps_handle_get_data(rktio, fc->lth)) { + /* Not zeroed, so never signaled. Change the auto behavior + to free the handle, and deregsiter the file descriptor. */ + rktio_ltps_handle_set_auto(rktio, fc->lth, RKTIO_LTPS_HANDLE_FREE); + (void)rktio_ltps_add(rktio, fc->lt, rfd, RKTIO_LTPS_REMOVE_VNODE); + } else { + /* Was signaled, so we need to free it. */ + free(fc->lth); + } rktio_close(rktio, rfd); - } else { - /* Was signaled, so we need to free it. */ - free(fc->lth); } #endif