From patchwork Wed Apr 10 13:23:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 235393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4EA102C0089 for ; Wed, 10 Apr 2013 23:24:14 +1000 (EST) Received: from localhost ([::1]:53384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPv0W-0002tF-H8 for incoming@patchwork.ozlabs.org; Wed, 10 Apr 2013 09:24:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPuzw-0002Z9-0y for qemu-devel@nongnu.org; Wed, 10 Apr 2013 09:23:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPuzu-00056N-O8 for qemu-devel@nongnu.org; Wed, 10 Apr 2013 09:23:35 -0400 Received: from mail-bk0-x22b.google.com ([2a00:1450:4008:c01::22b]:58196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPuzu-000567-Hc for qemu-devel@nongnu.org; Wed, 10 Apr 2013 09:23:34 -0400 Received: by mail-bk0-f43.google.com with SMTP id jm2so230359bkc.16 for ; Wed, 10 Apr 2013 06:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer; bh=X13bDF2022tVL4tSqwabcZmpBtxV+cN+6j60IpZlmPM=; b=FunY4nXhXvTfHk83Ve18gzoqL3HR7RvFZM93OWzOV16vApFt0r8goZYQaQsX8mwVU0 abQtbl8B8bdbUPNiuq14gBWfT0buejmqFJm/eAd26zgrbgXle90eSSgSJbxfCVdBW5yV QqDDRJwBALgHsDG93uq9ClzH5xTI7fJtzPcpALepN+YhegzYheM5AfWkw7bdDIXFxfjf CMTbv2z2z1fIBPk8aPe0PVuNr/eShDUSWFmNIfI2I6eGLt6Uh28KXkZ1AMYF1rycY8aN QDvDmJWiMzImW3GbJL1IdFk9XGikgnLc4PARqh/plQyES3AKBgm5mrQGne5jO+6IsVGu 3VQA== X-Received: by 10.204.191.17 with SMTP id dk17mr744067bkb.75.1365600213505; Wed, 10 Apr 2013 06:23:33 -0700 (PDT) Received: from playground.lan (93-34-176-20.ip50.fastwebnet.it. [93.34.176.20]) by mx.google.com with ESMTPS id gm14sm15869306bkc.7.2013.04.10.06.23.31 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 10 Apr 2013 06:23:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 10 Apr 2013 15:23:27 +0200 Message-Id: <1365600207-21685-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4008:c01::22b Cc: amit.shah@redhat.com, aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH] qemu-char: another io_add_watch_poll fix X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org After attaching the source, we have to remove the reference we hold to it, because we do not hold anymore a pointer to the source. If we do not do this, removing the source will not finalize it and will not drop the "real" I/O watch source. This showed up when backporting the new flow control patches to older versions of QEMU that still used select. The whole select then failed with EBADF (poll instead will reporting POLLNVAL on a single pollfd) and QEMU froze. Signed-off-by: Paolo Bonzini --- qemu-char.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qemu-char.c b/qemu-char.c index 37117b5..2caef56 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -610,6 +610,7 @@ static guint io_add_watch_poll(GIOChannel *channel, gpointer user_data) { IOWatchPoll *iwp; + int tag; iwp = (IOWatchPoll *) g_source_new(&io_watch_poll_funcs, sizeof(IOWatchPoll)); iwp->fd_can_read = fd_can_read; @@ -618,7 +619,9 @@ static guint io_add_watch_poll(GIOChannel *channel, iwp->fd_read = (GSourceFunc) fd_read; iwp->src = NULL; - return g_source_attach(&iwp->parent, NULL); + tag = g_source_attach(&iwp->parent, NULL); + g_source_unref(&iwp->parent); + return tag; } static GIOChannel *io_channel_from_fd(int fd)