XGE close_display hooks are not cleaned up if libXext.so is unloaded
libXext normally cleans up any XGE resources during display close. This can be an issue if libXext is unloaded before closing the display, as it will not clean up its resources and XGE's close_display hook will point to a library that is no longer present. In practice this was observed by libXext being automatically loaded/unloaded by a Vulkan instance. If the Vulkan instance is destroyed before closing the display it may unload libXext, causing a segfault when the close_display hook steps into the missing library.
The included program illustrates the problem. It loads libXext.so, registers GLX, unregisters GLX, and closes libXext.so. XCloseDisplay will then segfault as it calls the dangling close_display hook for XGE.
A possible resolution to this would be for libXext to clean up its resources when it is unloaded. Alternatively XGE could be removed from the display if all other extensions have also been removed.
Steps to reproduce on Linux:
$ gcc -std=c11 -O0 -g xge_repro.c -lvulkan -lX11 -ldl -o repro
$ ./repro <-- segmentation fault in XCloseDisplay()