@samitouri / QOSamiQemu / commits / b05c6e2532

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>

Marc-André Lureau committed Jun 23, 2026 at 11:44 UTC b05c6e2532059711e8e4f305b291ad4d9c1168f4
1 file changed +13
ui/console-vc.c
+13
@@ -255,6 +255,7 @@ static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
255 }
256
257 qemu_chr_be_event(chr, CHR_EVENT_OPENED);
258 + qemu_console_notify(QEMU_CONSOLE_ADDED, QEMU_CONSOLE(s));
259 return true;
260 }
261
@@ -327,12 +328,24 @@ static void char_vc_init(Object *obj)
328 vc->encoding = CHARDEV_VC_ENCODING_UTF8;
329 }
330
331 +static void char_vc_finalize(Object *obj)
332 +{
333 + VCChardev *vc = VC_CHARDEV(obj);
334 + QemuConsole *con = QEMU_CONSOLE(vc->console);
335 +
336 + if (con) {
337 + qemu_console_notify(QEMU_CONSOLE_REMOVED, con);
338 + object_unref(con);
339 + }
340 +}
341 +
342 static const TypeInfo char_vc_type_info = {
343 .name = TYPE_CHARDEV_VC,
344 .parent = TYPE_CHARDEV,
345 .instance_size = sizeof(VCChardev),
346 .instance_init = char_vc_init,
347 .instance_post_init = object_apply_compat_props,
348 + .instance_finalize = char_vc_finalize,
349 .class_init = char_vc_class_init,
350 };
351