diff --git a/fs/vfs/epoll/fs_epoll.c b/fs/vfs/epoll/fs_epoll.c index bdd9d7b86b9d4510ee67e1fde7dcf10a0582430a..cff2d41a3f9bddcb671eff8628af9bed5a3a242b 100644 --- a/fs/vfs/epoll/fs_epoll.c +++ b/fs/vfs/epoll/fs_epoll.c @@ -309,21 +309,22 @@ OUT_RELEASE: int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout) { struct epoll_head *epHead = NULL; - int ret; + int ret = -1; int counter; int i; struct pollfd *pFd = NULL; int pollSize; + (VOID)pthread_mutex_lock(&g_epollMutex); epHead = EpollGetDataBuff(epfd); if (epHead == NULL) { set_errno(EBADF); - return -1; + goto OUT_RELEASE; } if ((maxevents <= 0) || (evs == NULL)) { set_errno(EINVAL); - return -1; + goto OUT_RELEASE; } if (maxevents > epHead->nodeCount) { @@ -335,7 +336,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout pFd = malloc(sizeof(struct pollfd) * pollSize); if (pFd == NULL) { set_errno(EINVAL); - return -1; + goto OUT_RELEASE; } for (i = 0; i < pollSize; i++) { @@ -347,7 +348,8 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout ret = poll(pFd, pollSize, timeout); if (ret <= 0) { free(pFd); - return 0; + ret = 0; + goto OUT_RELEASE; } for (i = 0, counter = 0; i < ret && counter < pollSize; counter++) { @@ -359,6 +361,10 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout } free(pFd); - return i; + ret = i; + +OUT_RELEASE: + (VOID)pthread_mutex_unlock(&g_epollMutex); + return ret; }