[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/47] chardev: fix incorrect unref of source
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 09/47] chardev: fix incorrect unref of source |
Date: |
Mon, 5 Feb 2018 20:28:23 +0100 |
From: Peter Xu <address@hidden>
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 <address@hidden>
Reported-by: Marc-André Lureau <address@hidden>
Signed-off-by: Peter Xu <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
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 89315e6..68fd4e2 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.
--
1.8.3.1
- [Qemu-devel] [PULL 00/47] Misc patches for 2018-02-05, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 01/47] memory: update comments and fix some typos, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 02/47] qdev: rename typedef qdev_resetfn() -> DeviceReset(), Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 03/47] qdev: add helpers to be more explicit when using abstract QOM parent functions, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 05/47] kvm: Add kvm_set_user_memory tracepoint, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 06/47] qemu: improve hugepage allocation failure message, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 04/47] qdev: use device_class_set_parent_realize/unrealize/reset(), Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 07/47] memory: set ioeventfd_update_pending after address_space_update_ioeventfds, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 10/47] readline: don't free completions in readline_free(), Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 08/47] scsi-generic: Simplify error handling code, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 09/47] chardev: fix incorrect unref of source,
Paolo Bonzini <=
- [Qemu-devel] [PULL 11/47] scripts/qemu-gdb/timers.py: define encoding in header comment, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 12/47] memory-internal.h: Remove obsolete claim that header is obsolete, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 13/47] i2c: Add a CONFIG_I2C master switch to the configuration files, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 14/47] Add missing hvdos public domain attribution:, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 15/47] hvf: ept_emulation_fault() needs NetApp BSD attribution, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 18/47] exynos4210: workaround UBSAN compilation error, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 16/47] Drop remaining bits of ia64 host support, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 19/47] build-sys: add --enable-sanitizers, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 21/47] vhost: add traces for memory listeners, Paolo Bonzini, 2018/02/05
- [Qemu-devel] [PULL 20/47] ucontext: annotate coroutine stack for ASAN, Paolo Bonzini, 2018/02/05