From patchwork Thu Feb 7 13:23:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 10801207 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B97346C2 for ; Thu, 7 Feb 2019 13:25:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A82002B8D3 for ; Thu, 7 Feb 2019 13:25:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99EDC2897C; Thu, 7 Feb 2019 13:25:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4F09028CF5 for ; Thu, 7 Feb 2019 13:25:15 +0000 (UTC) Received: from localhost ([127.0.0.1]:40021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grjg2-00025Z-Bx for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Feb 2019 08:25:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grjeu-0001Dq-PI for qemu-devel@nongnu.org; Thu, 07 Feb 2019 08:24:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grjeu-0004Bg-58 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 08:24:04 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:59535) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1grjet-000405-Jo for qemu-devel@nongnu.org; Thu, 07 Feb 2019 08:24:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=4Q/+KF3PsMLpta38XReChATNDisWRfPvD05uJXO9Zic=; b=qYU04SU3KbOjsUpnSpqlLr81YUa6vieRMt125yQbmxPu+4x+/2SaL02/1hWZUodDvWoO7j6E8hOZxAXYijjqCvUO4x1YyMKd8zMwF+JfgIjA4H+1MQzy41wEjnUtaPkhb9GD24Muyp/5aUHRNhqp/rVCBd6UUdubnJ09dnB+xjUvVL7WfsdU3GM8UrUpOuaE9fBhJayNICAjfbmBp84cxh9hiECRaJK6eHNgryt2zx4FUcGEtS4MHwvu4N8gAv0uzba1qdAhMgqzDFlwFGOr6/wMy5UHsJRM8WYUVyw9sM1L8tGHSzwVGssce0GpGZ6TxtD1vEUAYSJpFcKJ4azv9A==; Received: from 62-165-147-230.co.dnainternet.fi ([62.165.147.230] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1grjeX-0003gm-Oh; Thu, 07 Feb 2019 14:23:41 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1grjeK-0003A3-OI; Thu, 07 Feb 2019 15:23:28 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 7 Feb 2019 15:23:21 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 1/3] main-loop: Don't leak GSources attached to a GMainContext X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Alberto Garcia , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP After g_source_attach() the GMainContext holds a reference to the GSource, so the caller does not need to keep it. pty_chr_state() and qio_task_thread_worker() are not doing this, so the GSource is being leaked in both cases (pty_chr_open_src_cancel() is the exception here because it does remove the extra reference correctly). Signed-off-by: Alberto Garcia Reviewed-by: Daniel P. Berrangé Reviewed-by: Marc-André Lureau --- chardev/char-pty.c | 2 +- io/task.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index f681d637c1..f16a5e8d59 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -60,7 +60,6 @@ static void pty_chr_open_src_cancel(PtyChardev *s) { if (s->open_source) { g_source_destroy(s->open_source); - g_source_unref(s->open_source); s->open_source = NULL; } } @@ -216,6 +215,7 @@ static void pty_chr_state(Chardev *chr, int connected) qemu_chr_be_generic_open_func, chr, NULL); g_source_attach(s->open_source, chr->gcontext); + g_source_unref(s->open_source); } if (!chr->gsource) { chr->gsource = io_add_watch_poll(chr, s->ioc, diff --git a/io/task.c b/io/task.c index 2886a2c1bc..c8489fb790 100644 --- a/io/task.c +++ b/io/task.c @@ -120,6 +120,7 @@ static gpointer qio_task_thread_worker(gpointer opaque) idle = g_idle_source_new(); g_source_set_callback(idle, qio_task_thread_result, data, NULL); g_source_attach(idle, data->context); + g_source_unref(idle); return NULL; }