[Qemu-devel] [PATCH] char-pty: avoid assertion warning

Peng Hao posted 1 patch 6 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1516923604-101518-1-git-send-email-peng.hao2@zte.com.cn
Test checkpatch passed
Test docker-build@min-glib passed
Test docker-mingw@fedora passed
Test docker-quick@centos6 failed
Test ppc passed
Test s390x passed
chardev/char-pty.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[Qemu-devel] [PATCH] char-pty: avoid assertion warning
Posted by Peng Hao 6 years, 2 months ago
g_source_unref(s->open_source) in pty_chr_timer may trigger a assertion like this:
g_source_unref: assertion 'source != NULL' failed.
pty_chr_update_read_handler_locked-->pty_chr_state(chr, 0) may be called
in pty_chr_timer, pty_chr_state(chr, 0) will call g_source_unref(s->open_source)
and set s->open_source=NULL.

Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
---
 chardev/char-pty.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index 89315e6..da0f286 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -58,8 +58,10 @@ static gboolean pty_chr_timer(gpointer opaque)
 
     qemu_mutex_lock(&chr->chr_write_lock);
     s->timer_src = NULL;
-    g_source_unref(s->open_source);
-    s->open_source = NULL;
+    if (s->open_source) {
+        g_source_unref(s->open_source);
+        s->open_source = NULL;
+    }
     if (!s->connected) {
         /* Next poll ... */
         pty_chr_update_read_handler_locked(chr);
-- 
1.8.3.1


Re: [Qemu-devel] [PATCH] char-pty: avoid assertion warning
Posted by Marc-Andre Lureau 6 years, 2 months ago
Hi

On Fri, Jan 26, 2018 at 12:40 AM, Peng Hao <peng.hao2@zte.com.cn> wrote:
> g_source_unref(s->open_source) in pty_chr_timer may trigger a assertion like this:
> g_source_unref: assertion 'source != NULL' failed.
> pty_chr_update_read_handler_locked-->pty_chr_state(chr, 0) may be called
> in pty_chr_timer, pty_chr_state(chr, 0) will call g_source_unref(s->open_source)
> and set s->open_source=NULL.

Peter already sent "[PATCH] chardev: fix incorrect unref of source",
queued by Paolo,
thanks

>
> Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
> ---
>  chardev/char-pty.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/chardev/char-pty.c b/chardev/char-pty.c
> index 89315e6..da0f286 100644
> --- a/chardev/char-pty.c
> +++ b/chardev/char-pty.c
> @@ -58,8 +58,10 @@ static gboolean pty_chr_timer(gpointer opaque)
>
>      qemu_mutex_lock(&chr->chr_write_lock);
>      s->timer_src = NULL;
> -    g_source_unref(s->open_source);
> -    s->open_source = NULL;
> +    if (s->open_source) {
> +        g_source_unref(s->open_source);
> +        s->open_source = NULL;
> +    }
>      if (!s->connected) {
>          /* Next poll ... */
>          pty_chr_update_read_handler_locked(chr);
> --
> 1.8.3.1
>