All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alberto Garcia <berto@igalia.com>
To: qemu-devel@nongnu.org
Cc: "Alberto Garcia" <berto@igalia.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH 1/3] main-loop: Don't leak GSources attached to a GMainContext
Date: Thu,  7 Feb 2019 15:23:21 +0200	[thread overview]
Message-ID: <c741408825d01f5a186901c5a8248126ffebe9fd.1549545591.git.berto@igalia.com> (raw)
In-Reply-To: <cover.1549545591.git.berto@igalia.com>
In-Reply-To: <cover.1549545591.git.berto@igalia.com>

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 <berto@igalia.com>
---
 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;
 }
-- 
2.11.0

  reply	other threads:[~2019-02-07 13:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-07 13:23 [Qemu-devel] [PATCH 0/3] char-socket: Fix race condition Alberto Garcia
2019-02-07 13:23 ` Alberto Garcia [this message]
2019-02-07 13:25   ` [Qemu-devel] [PATCH 1/3] main-loop: Don't leak GSources attached to a GMainContext Alberto Garcia
2019-02-07 14:21   ` Daniel P. Berrangé
2019-02-07 14:23   ` Marc-André Lureau
2019-02-07 14:24     ` Marc-André Lureau
2019-02-07 14:27       ` Alberto Garcia
2019-02-07 14:43         ` Marc-André Lureau
2019-02-07 14:47           ` Alberto Garcia
2019-02-07 13:23 ` [Qemu-devel] [PATCH 2/3] main-loop: Add qemu_idle_add() Alberto Garcia
2019-02-07 14:24   ` Daniel P. Berrangé
2019-02-07 14:28   ` Marc-André Lureau
2019-02-07 13:23 ` [Qemu-devel] [PATCH 3/3] char-socket: Lock tcp_chr_disconnect() and socket_reconnect_timeout() Alberto Garcia
2019-02-07 14:26   ` Daniel P. Berrangé
2019-02-08  8:50     ` Alberto Garcia
2019-02-08  9:34     ` Alberto Garcia
2019-02-08 13:46       ` Paolo Bonzini
2019-02-08 15:01         ` Alberto Garcia
2019-02-08 17:27           ` Paolo Bonzini
2019-02-07 14:46   ` Marc-André Lureau
2019-02-07 15:05     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c741408825d01f5a186901c5a8248126ffebe9fd.1549545591.git.berto@igalia.com \
    --to=berto@igalia.com \
    --cc=berrange@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.