This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 2969c8807e8 arch/sim: Stop publishing stale X11 display during 
teardown.
2969c8807e8 is described below

commit 2969c8807e898fa09b1eadb5664d73ef7a80e6f5
Author: hanzhijian <[email protected]>
AuthorDate: Mon May 25 13:02:02 2026 +0800

    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 <[email protected]>
---
 arch/sim/src/sim/posix/sim_x11framebuffer.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/sim/src/sim/posix/sim_x11framebuffer.c 
b/arch/sim/src/sim/posix/sim_x11framebuffer.c
index 68173ff5ee4..6b58be5d522 100644
--- a/arch/sim/src/sim/posix/sim_x11framebuffer.c
+++ b/arch/sim/src/sim/posix/sim_x11framebuffer.c
@@ -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);
 }
 
 /****************************************************************************

Reply via email to