From ff0414c8569abacfd8bd09e2055b0226fb42ce90 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Thu, 28 Apr 2016 22:00:54 +0100 Subject: [PATCH] librb: close FDs when they're freed (outside of select handler) --- librb/src/commio.c | 22 ++++++++++------------ librb/src/epoll.c | 3 --- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/librb/src/commio.c b/librb/src/commio.c index bd401b185..6b13518ec 100644 --- a/librb/src/commio.c +++ b/librb/src/commio.c @@ -110,6 +110,16 @@ free_fds(void) RB_DLINK_FOREACH_SAFE(ptr, next, closed_list.head) { F = ptr->data; + + number_fd--; + +#ifdef _WIN32 + if(F->type & (RB_FD_SOCKET | RB_FD_PIPE)) + closesocket(F->fd); + else +#endif + close(F->fd); + rb_dlinkDelete(ptr, &closed_list); rb_bh_free(fd_heap, F); } @@ -885,18 +895,6 @@ rb_close(rb_fde_t *F) remove_fd(F); ClearFDOpen(F); } - - number_fd--; - -#ifdef _WIN32 - if(type & (RB_FD_SOCKET | RB_FD_PIPE)) - { - closesocket(fd); - return; - } - else -#endif - close(fd); } diff --git a/librb/src/epoll.c b/librb/src/epoll.c index 7b5785c87..9af4bc674 100644 --- a/librb/src/epoll.c +++ b/librb/src/epoll.c @@ -188,9 +188,6 @@ rb_select_epoll(long delay) PF *hdl; rb_fde_t *F = ep_info->pfd[i].data.ptr; old_flags = F->pflags; - - if(!IsFDOpen(F)) - continue; if(ep_info->pfd[i].events & (EPOLLIN | EPOLLHUP | EPOLLERR)) { hdl = F->read_handler;