diff --git a/fs/vfs/fs_epoll.c b/fs/vfs/fs_epoll.c index 91181ea17c528..5cc98bd1281fe 100644 --- a/fs/vfs/fs_epoll.c +++ b/fs/vfs/fs_epoll.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "inode/inode.h" #include "fs_heap.h" @@ -203,6 +204,16 @@ static int epoll_do_close(FAR struct file *filep) file_put(epn->filep); } + list_for_every_entry(&eph->teardown, epn, epoll_node_t, node) + { + file_put(epn->filep); + } + + list_for_every_entry(&eph->oneshot, epn, epoll_node_t, node) + { + file_put(epn->filep); + } + list_for_every_entry_safe(&eph->extend, epn, tmp, epoll_node_t, node) { list_delete(&epn->node); @@ -384,6 +395,19 @@ static int epoll_teardown(FAR epoll_head_t *eph, FAR struct epoll_event *evs, return i; } +/**************************************************************************** + * Name: epoll_cleanup + * + * Description: + * Cleanup the epoll operation. + * + ****************************************************************************/ + +static void epoll_cleanup(FAR void *arg) +{ + file_put(arg); +} + /**************************************************************************** * Name: epoll_default_cb * @@ -744,6 +768,12 @@ int epoll_pwait(int epfd, FAR struct epoll_event *evs, nxsig_procmask(SIG_SETMASK, sigmask, &oldsigmask); + /* Push a cancellation point onto the stack. This will be called if + * the thread is canceled. + */ + + tls_cleanup_push(tls_get_info(), epoll_cleanup, filep); + if (timeout == 0) { ret = -ETIMEDOUT; @@ -757,6 +787,10 @@ int epoll_pwait(int epfd, FAR struct epoll_event *evs, ret = nxsem_wait(&eph->sem); } + /* Pop the cancellation point */ + + tls_cleanup_pop(tls_get_info(), 0); + nxsig_procmask(SIG_SETMASK, &oldsigmask, NULL); if (ret < 0 && ret != -ETIMEDOUT) { @@ -815,6 +849,12 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, goto err; } + /* Push a cancellation point onto the stack. This will be called if + * the thread is canceled. + */ + + tls_cleanup_push(tls_get_info(), epoll_cleanup, filep); + /* Wait the poll ready */ if (timeout == 0) @@ -830,6 +870,10 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, ret = nxsem_wait(&eph->sem); } + /* Pop the cancellation point */ + + tls_cleanup_pop(tls_get_info(), 0); + if (ret < 0 && ret != -ETIMEDOUT) { goto err;