From eea54988fd161a8bb80ae7b91382e5929c90de26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 13 Mar 2026 22:29:12 +0400 Subject: [PATCH] ui/vnc-jobs: clear source tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid potentially removing a dangling source & simplify code. Reviewed-by: Daniel P. Berrangé Signed-off-by: Marc-André Lureau --- ui/vnc-jobs.c | 4 +--- ui/vnc.c | 31 +++++++------------------------ 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c index ca625da6d0..ec90ae6d5f 100644 --- a/ui/vnc-jobs.c +++ b/ui/vnc-jobs.c @@ -162,9 +162,7 @@ void vnc_jobs_consume_buffer(VncState *vs) vnc_lock_output(vs); if (vs->jobs_buffer.offset) { if (vs->ioc != NULL && buffer_empty(&vs->output)) { - if (vs->ioc_tag) { - g_source_remove(vs->ioc_tag); - } + g_clear_handle_id(&vs->ioc_tag, g_source_remove); if (vs->disconnecting == FALSE) { vs->ioc_tag = qio_channel_add_watch( vs->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_OUT, diff --git a/ui/vnc.c b/ui/vnc.c index 952976e964..ccc73bd7aa 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -1301,10 +1301,7 @@ static void vnc_disconnect_start(VncState *vs) } trace_vnc_client_disconnect_start(vs, vs->ioc); vnc_set_share_mode(vs, VNC_SHARE_MODE_DISCONNECTED); - if (vs->ioc_tag) { - g_source_remove(vs->ioc_tag); - vs->ioc_tag = 0; - } + g_clear_handle_id(&vs->ioc_tag, g_source_remove); qio_channel_close(vs->ioc, NULL); vs->disconnecting = TRUE; } @@ -1462,9 +1459,7 @@ static size_t vnc_client_write_plain(VncState *vs) } if (vs->output.offset == 0) { - if (vs->ioc_tag) { - g_source_remove(vs->ioc_tag); - } + g_clear_handle_id(&vs->ioc_tag, g_source_remove); vs->ioc_tag = qio_channel_add_watch( vs->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR, vnc_client_io, vs, NULL); @@ -1500,9 +1495,7 @@ static void vnc_client_write(VncState *vs) if (vs->output.offset) { vnc_client_write_locked(vs); } else if (vs->ioc != NULL) { - if (vs->ioc_tag) { - g_source_remove(vs->ioc_tag); - } + g_clear_handle_id(&vs->ioc_tag, g_source_remove); vs->ioc_tag = qio_channel_add_watch( vs->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR, vnc_client_io, vs, NULL); @@ -1638,10 +1631,7 @@ gboolean vnc_client_io(QIOChannel *ioc G_GNUC_UNUSED, } if (vs->disconnecting) { - if (vs->ioc_tag != 0) { - g_source_remove(vs->ioc_tag); - } - vs->ioc_tag = 0; + g_clear_handle_id(&vs->ioc_tag, g_source_remove); } return TRUE; } @@ -1684,9 +1674,7 @@ void vnc_write(VncState *vs, const void *data, size_t len) buffer_reserve(&vs->output, len); if (vs->ioc != NULL && buffer_empty(&vs->output)) { - if (vs->ioc_tag) { - g_source_remove(vs->ioc_tag); - } + g_clear_handle_id(&vs->ioc_tag, g_source_remove); vs->ioc_tag = qio_channel_add_watch( vs->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_OUT, vnc_client_io, vs, NULL); @@ -1734,10 +1722,7 @@ void vnc_flush(VncState *vs) vnc_client_write_locked(vs); } if (vs->disconnecting) { - if (vs->ioc_tag != 0) { - g_source_remove(vs->ioc_tag); - } - vs->ioc_tag = 0; + g_clear_handle_id(&vs->ioc_tag, g_source_remove); } vnc_unlock_output(vs); } @@ -3342,9 +3327,7 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc, VNC_DEBUG("New client on socket %p\n", vs->sioc); update_displaychangelistener(&vd->dcl, VNC_REFRESH_INTERVAL_BASE); qio_channel_set_blocking(vs->ioc, false, &error_abort); - if (vs->ioc_tag) { - g_source_remove(vs->ioc_tag); - } + g_clear_handle_id(&vs->ioc_tag, g_source_remove); if (websocket) { vs->websocket = 1; if (vd->tlscreds) {