From 8d5557ef7da81e7f86b6f59c6348f3ef322ab37e Mon Sep 17 00:00:00 2001 From: zhaozihanzzh Date: Tue, 16 Jul 2024 21:45:54 +0800 Subject: [PATCH] Close kernel epoll fd in ff_hook_close when using FF_KERNEL_EVENT This commit fixes kernel fd leakage when using epoll in FF_KERNEL_EVENT. --- adapter/syscall/ff_hook_syscall.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/adapter/syscall/ff_hook_syscall.c b/adapter/syscall/ff_hook_syscall.c index 3681d1529..57010060e 100644 --- a/adapter/syscall/ff_hook_syscall.c +++ b/adapter/syscall/ff_hook_syscall.c @@ -1542,6 +1542,18 @@ ff_hook_close(int fd) SYSCALL(FF_SO_CLOSE, args); +#ifdef FF_KERNEL_EVENT + if (ret == 0 && fstack_kernel_fd_map[fd]) { + int kernel_fd_ret = ff_linux_close(fstack_kernel_fd_map[fd]); + if (kernel_fd_ret < 0) { + ERR_LOG("fstack_kernel_fd_map[%d]=%d, ff_linux_close returns %d, errno=%d\n", + fd, fstack_kernel_fd_map[fd], kernel_fd_ret, errno); + } else { + fstack_kernel_fd_map[fd] = 0; + } + } +#endif + RETURN_NOFREE(); }