@samitouri / QOSamiQemu / commits / f378a25b16

io: Clear dangling GLib event source tag

Following commit 34aad589019 ("hw/char/virtio-console: clear dangling GLib event source tag"), prevent stale tags from being reused by clearing dangling GLib event source tag during the cleanup phase (finalize, unrealize). Inspired-by: Matthew Penney <matt@matthewpenney.net> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Matthew Penney <matt@matthewpenney.net> Message-Id: <20260408100605.66795-2-philmd@linaro.org>

Philippe Mathieu-Daudé committed Apr 8, 2026 at 11:50 UTC f378a25b1646d33922af75aa7ea059b2123cfb13
3 files changed +4 -13
hw/usb/redirect.c
+1 -3
@@ -1494,9 +1494,7 @@ static void usbredir_unrealize(USBDevice *udev)
1494 if (dev->parser) {
1495 usbredirparser_destroy(dev->parser);
1496 }
1497 - if (dev->watch) {
1498 - g_source_remove(dev->watch);
1499 - }
1497 + g_clear_handle_id(&dev->watch, g_source_remove);
1498
1499 free(dev->filter_rules);
1500 qemu_del_vm_change_state_handler(dev->vmstate);
io/channel-websock.c
+2 -6
@@ -950,12 +950,8 @@ static void qio_channel_websock_finalize(Object *obj)
950 buffer_free(&ioc->encinput);
951 buffer_free(&ioc->encoutput);
952 buffer_free(&ioc->rawinput);
953 - if (ioc->hs_io_tag) {
954 - g_source_remove(ioc->hs_io_tag);
955 - }
956 - if (ioc->io_tag) {
957 - g_source_remove(ioc->io_tag);
958 - }
953 + g_clear_handle_id(&ioc->hs_io_tag, g_source_remove);
954 + g_clear_handle_id(&ioc->io_tag, g_source_remove);
955 error_free(ioc->io_err);
956 object_unref(OBJECT(ioc->master));
957 }
target/i386/kvm/tdx-quote-generator.c
+1 -4
@@ -74,10 +74,7 @@ static void encode_header(char *buf, size_t len, uint32_t size) {
74 static void tdx_generate_quote_cleanup(TdxGenerateQuoteTask *task)
75 {
76 timer_del(&task->timer);
77 -
78 - if (task->watch) {
79 - g_source_remove(task->watch);
80 - }
77 + g_clear_handle_id(&task->watch, g_source_remove);
78 qio_channel_close(QIO_CHANNEL(task->sioc), NULL);
79 object_unref(OBJECT(task->sioc));
80