Commit b05c6e2532 for qemu.org
commit b05c6e2532059711e8e4f305b291ad4d9c1168f4
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
Date: Tue Jun 23 11:44:40 2026 +0400
ui/console-vc: fire ADDED/REMOVED notifications
Fire CONSOLE_ADDED when the chardev is opened.
Fire CONSOLE_REMOVED in char_vc_finalize() before dropping the console
reference, so the console is still in a valid state when listeners
handle the event. Also fixes a console object leak by adding the
missing object_unref().
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260623-b4-ui-v4-25-4656aec3398d@redhat.com>
diff --git a/ui/console-vc.c b/ui/console-vc.c
index 828e78c41e..53d9e9d39b 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -255,6 +255,7 @@ static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
}
qemu_chr_be_event(chr, CHR_EVENT_OPENED);
+ qemu_console_notify(QEMU_CONSOLE_ADDED, QEMU_CONSOLE(s));
return true;
}
@@ -327,12 +328,24 @@ static void char_vc_init(Object *obj)
vc->encoding = CHARDEV_VC_ENCODING_UTF8;
}
+static void char_vc_finalize(Object *obj)
+{
+ VCChardev *vc = VC_CHARDEV(obj);
+ QemuConsole *con = QEMU_CONSOLE(vc->console);
+
+ if (con) {
+ qemu_console_notify(QEMU_CONSOLE_REMOVED, con);
+ object_unref(con);
+ }
+}
+
static const TypeInfo char_vc_type_info = {
.name = TYPE_CHARDEV_VC,
.parent = TYPE_CHARDEV,
.instance_size = sizeof(VCChardev),
.instance_init = char_vc_init,
.instance_post_init = object_apply_compat_props,
+ .instance_finalize = char_vc_finalize,
.class_init = char_vc_class_init,
};