arch/sim: Stop publishing stale X11 display during teardown.

sim_x11events() polls g_display from the idle loop while the
framebuffer teardown path closes the X connection.  Clear the global
Display handle before teardown so the event path stops using it, but
keep the saved local Display pointer for XShmDetach(), XUngrabButton(),
and XCloseDisplay().

This only changes the sim X11 framebuffer shutdown ordering and does
not change user-visible APIs or build configuration.

Signed-off-by: hanzhijian <hanzhijian@zepp.com>
This commit is contained in:
hanzhijian 2026-05-25 13:02:02 +08:00 committed by Alin Jerpelea
parent 4f512de7cb
commit 2969c8807e

View file

@ -217,15 +217,24 @@ static int sim_x11untraperrors(Display *display)
static void sim_x11uninit(void)
{
Display *display;
if (g_display == NULL)
{
return;
}
/* Publish shutdown before tearing down the X connection so the event
* polling path stops touching a stale Display pointer.
*/
display = g_display;
g_display = NULL;
#ifndef CONFIG_SIM_X11NOSHM
if (g_shmcheckpoint > 4)
{
XShmDetach(g_display, &g_xshminfo);
XShmDetach(display, &g_xshminfo);
}
if (g_shmcheckpoint > 3)
@ -251,10 +260,10 @@ static void sim_x11uninit(void)
#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK) || \
defined(CONFIG_SIM_BUTTONS)
XUngrabButton(g_display, Button1, AnyModifier, g_window);
XUngrabButton(display, Button1, AnyModifier, g_window);
#endif
XCloseDisplay(g_display);
XCloseDisplay(display);
}
/****************************************************************************