qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Xu <peterx@redhat.com>, qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] chardev: fix incorrect unref of source
Date: Thu, 18 Jan 2018 09:22:02 +0100	[thread overview]
Message-ID: <0eb8e22a-bc5e-9314-573e-28e8323c34f1@redhat.com> (raw)
In-Reply-To: <20180118052049.31119-1-peterx@redhat.com>

On 18/01/2018 06:20, Peter Xu wrote:
> glib reported error when pty chardev used:
> 
> $ ./qemu-system-x86_64 -chardev pty,id=foo -device isa-serial,chardev=foo
> qemu-system-x86_64: -chardev pty,id=foo: char device redirected to /dev/pts/2 (label foo)
> (qemu-system-x86_64:27885): GLib-CRITICAL **: g_source_unref: assertion 'source != NULL' failed
> (qemu-system-x86_64:27885): GLib-CRITICAL **: g_source_unref: assertion 'source != NULL' failed
> 
> This patch fixes that.
> 
> Fixes: 2c716ba150 ("chardev: introduce qemu_chr_timeout_add_ms()")
> CC: Paolo Bonzini <pbonzini@redhat.com>
> Reported-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  chardev/char-pty.c | 38 +++++++++++++++++++++-----------------
>  1 file changed, 21 insertions(+), 17 deletions(-)
> 
> diff --git a/chardev/char-pty.c b/chardev/char-pty.c
> index 89315e6807..68fd4e20c3 100644
> --- a/chardev/char-pty.c
> +++ b/chardev/char-pty.c
> @@ -51,15 +51,32 @@ typedef struct {
>  static void pty_chr_update_read_handler_locked(Chardev *chr);
>  static void pty_chr_state(Chardev *chr, int connected);
>  
> +static void pty_chr_timer_cancel(PtyChardev *s)
> +{
> +    if (s->timer_src) {
> +        g_source_destroy(s->timer_src);
> +        g_source_unref(s->timer_src);
> +        s->timer_src = NULL;
> +    }
> +}
> +
> +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;
> +    }
> +}
> +
>  static gboolean pty_chr_timer(gpointer opaque)
>  {
>      struct Chardev *chr = CHARDEV(opaque);
>      PtyChardev *s = PTY_CHARDEV(opaque);
>  
>      qemu_mutex_lock(&chr->chr_write_lock);
> -    s->timer_src = NULL;
> -    g_source_unref(s->open_source);
> -    s->open_source = NULL;
> +    pty_chr_timer_cancel(s);
> +    pty_chr_open_src_cancel(s);
>      if (!s->connected) {
>          /* Next poll ... */
>          pty_chr_update_read_handler_locked(chr);
> @@ -68,15 +85,6 @@ static gboolean pty_chr_timer(gpointer opaque)
>      return FALSE;
>  }
>  
> -static void pty_chr_timer_cancel(PtyChardev *s)
> -{
> -    if (s->timer_src) {
> -        g_source_destroy(s->timer_src);
> -        g_source_unref(s->timer_src);
> -        s->timer_src = NULL;
> -    }
> -}
> -
>  /* Called with chr_write_lock held.  */
>  static void pty_chr_rearm_timer(Chardev *chr, int ms)
>  {
> @@ -195,11 +203,7 @@ static void pty_chr_state(Chardev *chr, int connected)
>      PtyChardev *s = PTY_CHARDEV(chr);
>  
>      if (!connected) {
> -        if (s->open_source) {
> -            g_source_destroy(s->open_source);
> -            g_source_unref(s->open_source);
> -            s->open_source = NULL;
> -        }
> +        pty_chr_open_src_cancel(s);
>          remove_fd_in_watch(chr);
>          s->connected = 0;
>          /* (re-)connect poll interval for idle guests: once per second.
> 

Queued, thanks.

Paolo

      reply	other threads:[~2018-01-18  8:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-18  5:20 [Qemu-devel] [PATCH] chardev: fix incorrect unref of source Peter Xu
2018-01-18  8:22 ` Paolo Bonzini [this message]

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=0eb8e22a-bc5e-9314-573e-28e8323c34f1@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=peterx@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).