diff --git a/src/util/event_poll.c b/src/util/event_poll.c index dd83fc34a8..91000e29ab 100644 --- a/src/util/event_poll.c +++ b/src/util/event_poll.c @@ -354,7 +354,7 @@ static struct pollfd *virEventPollMakePollFDs(int *nfds) { *nfds = 0; for (i = 0 ; i < eventLoop.handlesCount ; i++) { - if (eventLoop.handles[i].events) + if (eventLoop.handles[i].events && !eventLoop.handles[i].deleted) (*nfds)++; } @@ -366,11 +366,12 @@ static struct pollfd *virEventPollMakePollFDs(int *nfds) { *nfds = 0; for (i = 0 ; i < eventLoop.handlesCount ; i++) { - EVENT_DEBUG("Prepare n=%d w=%d, f=%d e=%d", i, + EVENT_DEBUG("Prepare n=%d w=%d, f=%d e=%d d=%d", i, eventLoop.handles[i].watch, eventLoop.handles[i].fd, - eventLoop.handles[i].events); - if (!eventLoop.handles[i].events) + eventLoop.handles[i].events, + eventLoop.handles[i].deleted); + if (!eventLoop.handles[i].events || eventLoop.handles[i].deleted) continue; fds[*nfds].fd = eventLoop.handles[i].fd; fds[*nfds].events = eventLoop.handles[i].events; @@ -506,8 +507,13 @@ static void virEventPollCleanupTimeouts(void) { EVENT_DEBUG("Purging timeout %d with id %d", i, eventLoop.timeouts[i].timer); - if (eventLoop.timeouts[i].ff) - (eventLoop.timeouts[i].ff)(eventLoop.timeouts[i].opaque); + if (eventLoop.timeouts[i].ff) { + virFreeCallback ff = eventLoop.timeouts[i].ff; + void *opaque = eventLoop.timeouts[i].opaque; + virMutexUnlock(&eventLoop.lock); + ff(opaque); + virMutexLock(&eventLoop.lock); + } if ((i+1) < eventLoop.timeoutsCount) { memmove(eventLoop.timeouts+i, @@ -546,8 +552,13 @@ static void virEventPollCleanupHandles(void) { continue; } - if (eventLoop.handles[i].ff) - (eventLoop.handles[i].ff)(eventLoop.handles[i].opaque); + if (eventLoop.handles[i].ff) { + virFreeCallback ff = eventLoop.handles[i].ff; + void *opaque = eventLoop.handles[i].opaque; + virMutexUnlock(&eventLoop.lock); + ff(opaque); + virMutexLock(&eventLoop.lock); + } if ((i+1) < eventLoop.handlesCount) { memmove(eventLoop.handles+i,