ui/vnc-jobs: clear source tag
Avoid potentially removing a dangling source & simplify code. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Marc-André Lureau committed
Mar 13, 2026 at 22:29 UTC
eea54988fd161a8bb80ae7b91382e5929c90de26
2 files changed
+8
-27
ui/vnc-jobs.c
+1
-3
@@ -162,9 +162,7 @@ void vnc_jobs_consume_buffer(VncState *vs)
162
vnc_lock_output(vs);
163
if (vs->jobs_buffer.offset) {
164
if (vs->ioc != NULL && buffer_empty(&vs->output)) {
165
- if (vs->ioc_tag) {
166
- g_source_remove(vs->ioc_tag);
167
- }
165
+ g_clear_handle_id(&vs->ioc_tag, g_source_remove);
166
if (vs->disconnecting == FALSE) {
167
vs->ioc_tag = qio_channel_add_watch(
168
vs->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_OUT,
ui/vnc.c
+7
-24
@@ -1301,10 +1301,7 @@ static void vnc_disconnect_start(VncState *vs)
1301
}
1302
trace_vnc_client_disconnect_start(vs, vs->ioc);
1303
vnc_set_share_mode(vs, VNC_SHARE_MODE_DISCONNECTED);
1304
- if (vs->ioc_tag) {
1305
- g_source_remove(vs->ioc_tag);
1306
- vs->ioc_tag = 0;
1307
- }
1304
+ g_clear_handle_id(&vs->ioc_tag, g_source_remove);
1305
qio_channel_close(vs->ioc, NULL);
1306
vs->disconnecting = TRUE;
1307
}
@@ -1462,9 +1459,7 @@ static size_t vnc_client_write_plain(VncState *vs)
1459
}
1460
1461
if (vs->output.offset == 0) {
1465
- if (vs->ioc_tag) {
1466
- g_source_remove(vs->ioc_tag);
1467
- }
1462
+ g_clear_handle_id(&vs->ioc_tag, g_source_remove);
1463
vs->ioc_tag = qio_channel_add_watch(
1464
vs->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR,
1465
vnc_client_io, vs, NULL);
@@ -1500,9 +1495,7 @@ static void vnc_client_write(VncState *vs)
1495
if (vs->output.offset) {
1496
vnc_client_write_locked(vs);
1497
} else if (vs->ioc != NULL) {
1503
- if (vs->ioc_tag) {
1504
- g_source_remove(vs->ioc_tag);
1505
- }
1498
+ g_clear_handle_id(&vs->ioc_tag, g_source_remove);
1499
vs->ioc_tag = qio_channel_add_watch(
1500
vs->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR,
1501
vnc_client_io, vs, NULL);
@@ -1638,10 +1631,7 @@ gboolean vnc_client_io(QIOChannel *ioc G_GNUC_UNUSED,
1631
}
1632
1633
if (vs->disconnecting) {
1641
- if (vs->ioc_tag != 0) {
1642
- g_source_remove(vs->ioc_tag);
1643
- }
1644
- vs->ioc_tag = 0;
1634
+ g_clear_handle_id(&vs->ioc_tag, g_source_remove);
1635
}
1636
return TRUE;
1637
}
@@ -1684,9 +1674,7 @@ void vnc_write(VncState *vs, const void *data, size_t len)
1674
buffer_reserve(&vs->output, len);
1675
1676
if (vs->ioc != NULL && buffer_empty(&vs->output)) {
1687
- if (vs->ioc_tag) {
1688
- g_source_remove(vs->ioc_tag);
1689
- }
1677
+ g_clear_handle_id(&vs->ioc_tag, g_source_remove);
1678
vs->ioc_tag = qio_channel_add_watch(
1679
vs->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_OUT,
1680
vnc_client_io, vs, NULL);
@@ -1734,10 +1722,7 @@ void vnc_flush(VncState *vs)
1722
vnc_client_write_locked(vs);
1723
}
1724
if (vs->disconnecting) {
1737
- if (vs->ioc_tag != 0) {
1738
- g_source_remove(vs->ioc_tag);
1739
- }
1740
- vs->ioc_tag = 0;
1725
+ g_clear_handle_id(&vs->ioc_tag, g_source_remove);
1726
}
1727
vnc_unlock_output(vs);
1728
}
@@ -3342,9 +3327,7 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc,
3327
VNC_DEBUG("New client on socket %p\n", vs->sioc);
3328
update_displaychangelistener(&vd->dcl, VNC_REFRESH_INTERVAL_BASE);
3329
qio_channel_set_blocking(vs->ioc, false, &error_abort);
3345
- if (vs->ioc_tag) {
3346
- g_source_remove(vs->ioc_tag);
3347
- }
3330
+ g_clear_handle_id(&vs->ioc_tag, g_source_remove);
3331
if (websocket) {
3332
vs->websocket = 1;
3333
if (vd->tlscreds) {