Skip to contentSkip to conversation

char-pty: avoid assertion warning

PATCH In review Peng Hao 2 participants 2 messages Jan 25, 2018

lore
Share & tools
lore

Peng Hao

author
#0 lore raw

PATCH 1/1 char-pty: avoid assertion warning

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.

---
 chardev/char-pty.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
chardev/char-pty.c +4 -2
index 89315e6..da0f286 100644
@@ -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);
Signature · 1 line
1.8.3.1
#1 lore raw

Hi

Quoted 5 lines · Peng Hao

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

Quoted 26 lines
---
 chardev/char-pty.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
chardev/char-pty.c +4 -3
index 89315e6..da0f286 100644
@@ -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