---
vl.c | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/vl.c b/vl.c
index 7038952..6f56123 100644
--- a/vl.c
+++ b/vl.c
@@ -1252,17 +1252,18 @@ void main_loop_wait(int nonblocking)
IOHandlerRecord *pioh;
QLIST_FOREACH_SAFE(ioh,&io_handlers, next, pioh) {
- if (ioh->deleted) {
- QLIST_REMOVE(ioh, next);
- qemu_free(ioh);
- continue;
- }
- if (ioh->fd_read&& FD_ISSET(ioh->fd,&rfds)) {
+ if (!ioh->deleted&& ioh->fd_read&& FD_ISSET(ioh->fd,&rfds)) {
ioh->fd_read(ioh->opaque);
}
- if (ioh->fd_write&& FD_ISSET(ioh->fd,&wfds)) {
+ if (!ioh->deleted&& ioh->fd_write&& FD_ISSET(ioh->fd,&wfds)) {
ioh->fd_write(ioh->opaque);
}
+
+ /* Do this last in case read/write handlers marked it for deletion
*/
+ if (ioh->deleted) {
+ QLIST_REMOVE(ioh, next);
+ qemu_free(ioh);
+ }
}
}