diff --git a/fs/vfs/fs_epoll.c b/fs/vfs/fs_epoll.c index 42448071276..5cc98bd1281 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" @@ -394,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 * @@ -754,6 +768,12 @@ retry: 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; @@ -767,6 +787,10 @@ retry: 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) { @@ -825,6 +849,12 @@ retry: 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) @@ -840,6 +870,10 @@ retry: ret = nxsem_wait(&eph->sem); } + /* Pop the cancellation point */ + + tls_cleanup_pop(tls_get_info(), 0); + if (ret < 0 && ret != -ETIMEDOUT) { goto err;