ui/curses: implement display cleanup
Replace the atexit() handler with a proper cleanup callback. The new curses_cleanup() unregisters the display listener, destroy & free the allocated resources. 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-16-4656aec3398d@redhat.com>
Marc-André Lureau committed
Jun 23, 2026 at 11:44 UTC
721eafa5de92a1944502ad8ad8b59d344d35ccaa
1 file changed
+12
-5
ui/curses.c
+12
-5
@@ -411,11 +411,19 @@ static void curses_refresh(DisplayChangeListener *dcl)
411
}
412
}
413
414
-static void curses_atexit(void)
414
+static void curses_cleanup(void)
415
{
416
+ if (!dcl) {
417
+ return;
418
+ }
419
+
420
endwin();
417
- g_free(vga_to_curses);
418
- g_free(screen);
421
+ qemu_console_unregister_listener(dcl);
422
+ g_clear_pointer(&dcl, g_free);
423
+ g_clear_pointer(&screenpad, delwin);
424
+ g_clear_pointer(&vga_to_curses, g_free);
425
+ g_clear_pointer(&screen, g_free);
426
+ g_clear_pointer(&kbd_layout, kbd_layout_free);
427
}
428
429
/*
@@ -799,8 +807,6 @@ static void curses_display_init(DisplayState *ds, DisplayOptions *opts)
807
vga_to_curses = g_new0(cchar_t, 256);
808
curses_setup();
809
curses_keyboard_setup();
802
- atexit(curses_atexit);
803
-
810
curses_winch_init();
811
812
dcl = g_new0(DisplayChangeListener, 1);
@@ -812,6 +818,7 @@ static void curses_display_init(DisplayState *ds, DisplayOptions *opts)
818
static QemuDisplay qemu_display_curses = {
819
.type = DISPLAY_TYPE_CURSES,
820
.init = curses_display_init,
821
+ .cleanup = curses_cleanup,
822
};
823
824
static void register_curses(void)