From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=47251 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDeLZ-0001Xz-48 for qemu-devel@nongnu.org; Wed, 03 Nov 2010 10:29:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDeLX-0006Jy-Uj for qemu-devel@nongnu.org; Wed, 03 Nov 2010 10:29:52 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:48041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDeLX-0006Jb-NV for qemu-devel@nongnu.org; Wed, 03 Nov 2010 10:29:51 -0400 Received: from d06nrmr1507.portsmouth.uk.ibm.com (d06nrmr1507.portsmouth.uk.ibm.com [9.149.38.233]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id oA3ETnMo004300 for ; Wed, 3 Nov 2010 14:29:49 GMT Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oA3ETp622891818 for ; Wed, 3 Nov 2010 14:29:51 GMT Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oA3ETmQB011257 for ; Wed, 3 Nov 2010 08:29:48 -0600 From: Stefan Hajnoczi Date: Wed, 3 Nov 2010 14:29:44 +0000 Message-Id: <1288794584-6099-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] Delete IOHandlers after potentially running them List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Juan Quintela Since commit 4bed9837309e58d208183f81d8344996744292cf an .fd_read() handler that deletes its IOHandler is exposed to .fd_write() being called on the deleted IOHandler. This patch fixes deletion so that .fd_read() and .fd_write() are never called on an IOHandler that is marked for deletion. Signed-off-by: Stefan Hajnoczi --- 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); + } } } -- 1.7.2.3