XWindowSystem related Segfault on quitting a Gui App (JUCE v7.0.2)

I recently started getting a random segfault when closing my juce GUI app window. As it’s random, it’s hard to tell exactly which feature triggered the problem. Gdb gives the following:

Thread 1 "MyJuceApp" received signal SIGSEGV, Segmentation fault.
0x00007ffff788b0c1 in unlink_chunk (p=p@entry=0x5555562af1a0, av=0x7ffff79d1aa0 <main_arena>) at malloc.c:1610
1610      if (__builtin_expect (fd->bk != p || bk->fd != p, 0))
(gdb) bt
#0  0x00007ffff788b0c1 in unlink_chunk (p=p@entry=0x5555562af1a0, av=0x7ffff79d1aa0 <main_arena>) at malloc.c:1610
#1  0x00007ffff788c1f0 in _int_free (av=0x7ffff79d1aa0 <main_arena>, p=0x5555562af1a0, have_lock=<optimized out>, have_lock@entry=0) at malloc.c:4593
#2  0x00007ffff788ee63 in __GI___libc_free (mem=<optimized out>) at malloc.c:3367
#3  0x00007ffff735951c in _XFreeDisplayStructure (dpy=0x555556291f70) at /usr/src/debug/libx11/libX11-1.8.4/src/OpenDis.c:680
#4  0x00007ffff734be34 in XCloseDisplay (dpy=0x555556291f70) at /usr/src/debug/libx11/libX11-1.8.4/src/ClDisplay.c:72
#5  0x0000555555743b13 in juce::XWindowSystem::destroyXDisplay (this=0x55555628c2a0) at /path/to/my/juce/project/JUCE/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp:3255
#6  0x000055555573b630 in juce::XWindowSystem::~XWindowSystem (this=0x55555628c2a0, __in_chrg=<optimized out>)
    at /path/to/my/juce/project/JUCE/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp:1494
#7  0x000055555573b6d0 in juce::XWindowSystem::~XWindowSystem (this=0x55555628c2a0, __in_chrg=<optimized out>)
    at /path/to/my/juce/project/JUCE/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp:1502
#8  0x000055555599e2ff in juce::DeletedAtShutdown::deleteAll () at /path/to/my/juce/project/JUCE/modules/juce_events/messages/juce_DeletedAtShutdown.cpp:75
#9  0x000055555599f67c in juce::shutdownJuce_GUI () at /path/to/my/juce/project/JUCE/modules/juce_events/messages/juce_MessageManager.cpp:477
#10 0x000055555599f6df in juce::ScopedJuceInitialiser_GUI::~ScopedJuceInitialiser_GUI (this=0x7fffffffd9bf, __in_chrg=<optimized out>)
    at /path/to/my/juce/project/JUCE/modules/juce_events/messages/juce_MessageManager.cpp:485
#11 0x000055555599ddf7 in juce::JUCEApplicationBase::main () at /path/to/my/juce/project/JUCE/modules/juce_events/messages/juce_ApplicationBase.cpp:267
#12 0x000055555599dcc4 in juce::JUCEApplicationBase::main (argc=1, argv=0x7fffffffdb38) at /path/to/my/juce/project/JUCE/modules/juce_events/messages/juce_ApplicationBase.cpp:240
#13 0x000055555561fd72 in main (argc=1, argv=0x7fffffffdb38) at /path/to/my/juce/project/src/Main.cpp:120
(gdb) 

It’s only a mild annoyance as the app runs fine, and the segfault happens randomly when closing the window, but I’d gladly fix it if anyone has an idea.

Output of uname -a:

Linux my-user-name 6.2.1-arch1-1 #1 SMP PREEMPT_DYNAMIC Sun, 26 Feb 2023 03:39:23 +0000 x86_64 GNU/Linux

I use Wayland with Hyprland and the wayland-info gives the following:

interface: 'wl_shm',                                     version:  1, name:  1
	formats (fourcc):
	0x38344241 = 'AB48'
	0x38344258 = 'XB48'
	0x48344241 = 'AB4H'
	0x48344258 = 'XB4H'
	0x30334241 = 'AB30'
	0x30334258 = 'XB30'
	0x36314752 = 'RG16'
	0x35314152 = 'RA15'
	0x35315852 = 'RX15'
	0x32314152 = 'RA12'
	0x32315852 = 'RX12'
	0x34324742 = 'BG24'
	0x34324241 = 'AB24'
	0x34324258 = 'XB24'
	         1 = 'XR24'
	         0 = 'AR24'
interface: 'wl_drm',                                     version:  2, name:  2
interface: 'zwp_linux_dmabuf_v1',                        version:  4, name:  3
	main device: 0xE280
	tranche
		target device: 0xE280
		flags: none
		formats (fourcc) and modifiers (names):
		0x48344241 = 'AB4H'; 0x0000000000000000 = LINEAR
		0x48344241 = 'AB4H'; 0x0100000000000001 = INTEL_X_TILED
		0x48344241 = 'AB4H'; 0x0100000000000002 = INTEL_Y_TILED
		0x48344241 = 'AB4H'; 0x00ffffffffffffff = INVALID
		0x48344258 = 'XB4H'; 0x0000000000000000 = LINEAR
		0x48344258 = 'XB4H'; 0x0100000000000001 = INTEL_X_TILED
		0x48344258 = 'XB4H'; 0x0100000000000002 = INTEL_Y_TILED
		0x48344258 = 'XB4H'; 0x00ffffffffffffff = INVALID
		0x38344241 = 'AB48'; 0x0000000000000000 = LINEAR
		0x38344241 = 'AB48'; 0x0100000000000001 = INTEL_X_TILED
		0x38344241 = 'AB48'; 0x0100000000000002 = INTEL_Y_TILED
		0x38344241 = 'AB48'; 0x00ffffffffffffff = INVALID
		0x38344258 = 'XB48'; 0x0000000000000000 = LINEAR
		0x38344258 = 'XB48'; 0x0100000000000001 = INTEL_X_TILED
		0x38344258 = 'XB48'; 0x0100000000000002 = INTEL_Y_TILED
		0x38344258 = 'XB48'; 0x00ffffffffffffff = INVALID
		0x30335241 = 'AR30'; 0x0000000000000000 = LINEAR
		0x30335241 = 'AR30'; 0x0100000000000001 = INTEL_X_TILED
		0x30335241 = 'AR30'; 0x0100000000000002 = INTEL_Y_TILED
		0x30335241 = 'AR30'; 0x00ffffffffffffff = INVALID
		0x30335258 = 'XR30'; 0x0000000000000000 = LINEAR
		0x30335258 = 'XR30'; 0x0100000000000001 = INTEL_X_TILED
		0x30335258 = 'XR30'; 0x0100000000000002 = INTEL_Y_TILED
		0x30335258 = 'XR30'; 0x00ffffffffffffff = INVALID
		0x30334241 = 'AB30'; 0x0000000000000000 = LINEAR
		0x30334241 = 'AB30'; 0x0100000000000001 = INTEL_X_TILED
		0x30334241 = 'AB30'; 0x0100000000000002 = INTEL_Y_TILED
		0x30334241 = 'AB30'; 0x00ffffffffffffff = INVALID
		0x34325241 = 'AR24'; 0x0000000000000000 = LINEAR
		0x34325241 = 'AR24'; 0x0100000000000001 = INTEL_X_TILED
		0x34325241 = 'AR24'; 0x0100000000000002 = INTEL_Y_TILED
		0x34325241 = 'AR24'; 0x00ffffffffffffff = INVALID
		0x34324241 = 'AB24'; 0x0000000000000000 = LINEAR
		0x34324241 = 'AB24'; 0x0100000000000001 = INTEL_X_TILED
		0x34324241 = 'AB24'; 0x0100000000000002 = INTEL_Y_TILED
		0x34324241 = 'AB24'; 0x00ffffffffffffff = INVALID
		0x34325258 = 'XR24'; 0x0000000000000000 = LINEAR
		0x34325258 = 'XR24'; 0x0100000000000001 = INTEL_X_TILED
		0x34325258 = 'XR24'; 0x0100000000000002 = INTEL_Y_TILED
		0x34325258 = 'XR24'; 0x00ffffffffffffff = INVALID
		0x34324258 = 'XB24'; 0x0000000000000000 = LINEAR
		0x34324258 = 'XB24'; 0x0100000000000001 = INTEL_X_TILED
		0x34324258 = 'XB24'; 0x0100000000000002 = INTEL_Y_TILED
		0x34324258 = 'XB24'; 0x00ffffffffffffff = INVALID
		0x35315241 = 'AR15'; 0x0000000000000000 = LINEAR
		0x35315241 = 'AR15'; 0x0100000000000001 = INTEL_X_TILED
		0x35315241 = 'AR15'; 0x0100000000000002 = INTEL_Y_TILED
		0x35315241 = 'AR15'; 0x00ffffffffffffff = INVALID
		0x36314752 = 'RG16'; 0x0000000000000000 = LINEAR
		0x36314752 = 'RG16'; 0x0100000000000001 = INTEL_X_TILED
		0x36314752 = 'RG16'; 0x0100000000000002 = INTEL_Y_TILED
		0x36314752 = 'RG16'; 0x00ffffffffffffff = INVALID
		0x20203852 = 'R8  '; 0x0000000000000000 = LINEAR
		0x20203852 = 'R8  '; 0x0100000000000001 = INTEL_X_TILED
		0x20203852 = 'R8  '; 0x0100000000000002 = INTEL_Y_TILED
		0x20203852 = 'R8  '; 0x00ffffffffffffff = INVALID
		0x20363152 = 'R16 '; 0x0000000000000000 = LINEAR
		0x20363152 = 'R16 '; 0x0100000000000001 = INTEL_X_TILED
		0x20363152 = 'R16 '; 0x0100000000000002 = INTEL_Y_TILED
		0x20363152 = 'R16 '; 0x00ffffffffffffff = INVALID
		0x38385247 = 'GR88'; 0x0000000000000000 = LINEAR
		0x38385247 = 'GR88'; 0x0100000000000001 = INTEL_X_TILED
		0x38385247 = 'GR88'; 0x0100000000000002 = INTEL_Y_TILED
		0x38385247 = 'GR88'; 0x00ffffffffffffff = INVALID
		0x32335247 = 'GR32'; 0x0000000000000000 = LINEAR
		0x32335247 = 'GR32'; 0x0100000000000001 = INTEL_X_TILED
		0x32335247 = 'GR32'; 0x0100000000000002 = INTEL_Y_TILED
		0x32335247 = 'GR32'; 0x00ffffffffffffff = INVALID
		0x39565559 = 'YUV9'; 0x0000000000000000 = LINEAR
		0x39565559 = 'YUV9'; 0x0100000000000001 = INTEL_X_TILED
		0x39565559 = 'YUV9'; 0x0100000000000002 = INTEL_Y_TILED
		0x39565559 = 'YUV9'; 0x00ffffffffffffff = INVALID
		0x31315559 = 'YU11'; 0x0000000000000000 = LINEAR
		0x31315559 = 'YU11'; 0x0100000000000001 = INTEL_X_TILED
		0x31315559 = 'YU11'; 0x0100000000000002 = INTEL_Y_TILED
		0x31315559 = 'YU11'; 0x00ffffffffffffff = INVALID
		0x32315559 = 'YU12'; 0x0000000000000000 = LINEAR
		0x32315559 = 'YU12'; 0x0100000000000001 = INTEL_X_TILED
		0x32315559 = 'YU12'; 0x0100000000000002 = INTEL_Y_TILED
		0x32315559 = 'YU12'; 0x00ffffffffffffff = INVALID
		0x36315559 = 'YU16'; 0x0000000000000000 = LINEAR
		0x36315559 = 'YU16'; 0x0100000000000001 = INTEL_X_TILED
		0x36315559 = 'YU16'; 0x0100000000000002 = INTEL_Y_TILED
		0x36315559 = 'YU16'; 0x00ffffffffffffff = INVALID
		0x34325559 = 'YU24'; 0x0000000000000000 = LINEAR
		0x34325559 = 'YU24'; 0x0100000000000001 = INTEL_X_TILED
		0x34325559 = 'YU24'; 0x0100000000000002 = INTEL_Y_TILED
		0x34325559 = 'YU24'; 0x00ffffffffffffff = INVALID
		0x39555659 = 'YVU9'; 0x0000000000000000 = LINEAR
		0x39555659 = 'YVU9'; 0x0100000000000001 = INTEL_X_TILED
		0x39555659 = 'YVU9'; 0x0100000000000002 = INTEL_Y_TILED
		0x39555659 = 'YVU9'; 0x00ffffffffffffff = INVALID
		0x31315659 = 'YV11'; 0x0000000000000000 = LINEAR
		0x31315659 = 'YV11'; 0x0100000000000001 = INTEL_X_TILED
		0x31315659 = 'YV11'; 0x0100000000000002 = INTEL_Y_TILED
		0x31315659 = 'YV11'; 0x00ffffffffffffff = INVALID
		0x32315659 = 'YV12'; 0x0000000000000000 = LINEAR
		0x32315659 = 'YV12'; 0x0100000000000001 = INTEL_X_TILED
		0x32315659 = 'YV12'; 0x0100000000000002 = INTEL_Y_TILED
		0x32315659 = 'YV12'; 0x00ffffffffffffff = INVALID
		0x36315659 = 'YV16'; 0x0000000000000000 = LINEAR
		0x36315659 = 'YV16'; 0x0100000000000001 = INTEL_X_TILED
		0x36315659 = 'YV16'; 0x0100000000000002 = INTEL_Y_TILED
		0x36315659 = 'YV16'; 0x00ffffffffffffff = INVALID
		0x34325659 = 'YV24'; 0x0000000000000000 = LINEAR
		0x34325659 = 'YV24'; 0x0100000000000001 = INTEL_X_TILED
		0x34325659 = 'YV24'; 0x0100000000000002 = INTEL_Y_TILED
		0x34325659 = 'YV24'; 0x00ffffffffffffff = INVALID
		0x3231564e = 'NV12'; 0x0000000000000000 = LINEAR
		0x3231564e = 'NV12'; 0x0100000000000001 = INTEL_X_TILED
		0x3231564e = 'NV12'; 0x0100000000000002 = INTEL_Y_TILED
		0x3231564e = 'NV12'; 0x00ffffffffffffff = INVALID
		0x30313050 = 'P010'; 0x0000000000000000 = LINEAR
		0x30313050 = 'P010'; 0x0100000000000001 = INTEL_X_TILED
		0x30313050 = 'P010'; 0x0100000000000002 = INTEL_Y_TILED
		0x30313050 = 'P010'; 0x00ffffffffffffff = INVALID
		0x32313050 = 'P012'; 0x0000000000000000 = LINEAR
		0x32313050 = 'P012'; 0x0100000000000001 = INTEL_X_TILED
		0x32313050 = 'P012'; 0x0100000000000002 = INTEL_Y_TILED
		0x32313050 = 'P012'; 0x00ffffffffffffff = INVALID
		0x36313050 = 'P016'; 0x0000000000000000 = LINEAR
		0x36313050 = 'P016'; 0x0100000000000001 = INTEL_X_TILED
		0x36313050 = 'P016'; 0x0100000000000002 = INTEL_Y_TILED
		0x36313050 = 'P016'; 0x00ffffffffffffff = INVALID
		0x3631564e = 'NV16'; 0x0000000000000000 = LINEAR
		0x3631564e = 'NV16'; 0x0100000000000001 = INTEL_X_TILED
		0x3631564e = 'NV16'; 0x0100000000000002 = INTEL_Y_TILED
		0x3631564e = 'NV16'; 0x00ffffffffffffff = INVALID
		0x56555941 = 'AYUV'; 0x0000000000000000 = LINEAR
		0x56555941 = 'AYUV'; 0x0100000000000001 = INTEL_X_TILED
		0x56555941 = 'AYUV'; 0x0100000000000002 = INTEL_Y_TILED
		0x56555941 = 'AYUV'; 0x00ffffffffffffff = INVALID
		0x56555958 = 'XYUV'; 0x0000000000000000 = LINEAR
		0x56555958 = 'XYUV'; 0x0100000000000001 = INTEL_X_TILED
		0x56555958 = 'XYUV'; 0x0100000000000002 = INTEL_Y_TILED
		0x56555958 = 'XYUV'; 0x00ffffffffffffff = INVALID
		0x30313459 = 'Y410'; 0x0000000000000000 = LINEAR
		0x30313459 = 'Y410'; 0x0100000000000001 = INTEL_X_TILED
		0x30313459 = 'Y410'; 0x0100000000000002 = INTEL_Y_TILED
		0x30313459 = 'Y410'; 0x00ffffffffffffff = INVALID
		0x32313459 = 'Y412'; 0x0000000000000000 = LINEAR
		0x32313459 = 'Y412'; 0x0100000000000001 = INTEL_X_TILED
		0x32313459 = 'Y412'; 0x0100000000000002 = INTEL_Y_TILED
		0x32313459 = 'Y412'; 0x00ffffffffffffff = INVALID
		0x36313459 = 'Y416'; 0x0000000000000000 = LINEAR
		0x36313459 = 'Y416'; 0x0100000000000001 = INTEL_X_TILED
		0x36313459 = 'Y416'; 0x0100000000000002 = INTEL_Y_TILED
		0x36313459 = 'Y416'; 0x00ffffffffffffff = INVALID
		0x56595559 = 'YUYV'; 0x0000000000000000 = LINEAR
		0x56595559 = 'YUYV'; 0x0100000000000001 = INTEL_X_TILED
		0x56595559 = 'YUYV'; 0x0100000000000002 = INTEL_Y_TILED
		0x56595559 = 'YUYV'; 0x00ffffffffffffff = INVALID
		0x59565955 = 'UYVY'; 0x0000000000000000 = LINEAR
		0x59565955 = 'UYVY'; 0x0100000000000001 = INTEL_X_TILED
		0x59565955 = 'UYVY'; 0x0100000000000002 = INTEL_Y_TILED
		0x59565955 = 'UYVY'; 0x00ffffffffffffff = INVALID
		0x30313259 = 'Y210'; 0x0000000000000000 = LINEAR
		0x30313259 = 'Y210'; 0x0100000000000001 = INTEL_X_TILED
		0x30313259 = 'Y210'; 0x0100000000000002 = INTEL_Y_TILED
		0x30313259 = 'Y210'; 0x00ffffffffffffff = INVALID
		0x32313259 = 'Y212'; 0x0000000000000000 = LINEAR
		0x32313259 = 'Y212'; 0x0100000000000001 = INTEL_X_TILED
		0x32313259 = 'Y212'; 0x0100000000000002 = INTEL_Y_TILED
		0x32313259 = 'Y212'; 0x00ffffffffffffff = INVALID
		0x36313259 = 'Y216'; 0x0000000000000000 = LINEAR
		0x36313259 = 'Y216'; 0x0100000000000001 = INTEL_X_TILED
		0x36313259 = 'Y216'; 0x0100000000000002 = INTEL_Y_TILED
		0x36313259 = 'Y216'; 0x00ffffffffffffff = INVALID
interface: 'wl_compositor',                              version:  5, name:  4
interface: 'wl_subcompositor',                           version:  1, name:  5
interface: 'wl_data_device_manager',                     version:  3, name:  6
interface: 'zwlr_export_dmabuf_manager_v1',              version:  1, name:  7
interface: 'zwlr_screencopy_manager_v1',                 version:  3, name:  8
interface: 'zwlr_data_control_manager_v1',               version:  2, name:  9
interface: 'zwlr_gamma_control_manager_v1',              version:  1, name: 10
interface: 'zwp_primary_selection_device_manager_v1',    version:  1, name: 11
interface: 'wp_viewporter',                              version:  1, name: 12
interface: 'zwlr_output_power_manager_v1',               version:  1, name: 13
interface: 'xdg_wm_base',                                version:  5, name: 14
interface: 'wl_seat',                                    version:  8, name: 15
	name: seat0
	capabilities: pointer keyboard
	keyboard repeat rate: 25
	keyboard repeat delay: 600
interface: 'wp_presentation',                            version:  1, name: 16
	presentation clock id: 1 (CLOCK_MONOTONIC)
interface: 'org_kde_kwin_idle',                          version:  1, name: 17
interface: 'zwlr_layer_shell_v1',                        version:  4, name: 18
interface: 'org_kde_kwin_server_decoration_manager',     version:  1, name: 19
interface: 'zxdg_decoration_manager_v1',                 version:  1, name: 20
interface: 'zxdg_output_manager_v1',                     version:  3, name: 21
	xdg_output_v1
		output: 47
		name: 'HDMI-A-2'
		description: 'ASUSTek COMPUTER INC ASUS VA27EHE N2LMTF151742 (HDMI-A-2)'
		logical_x: 1920, logical_y: 0
		logical_width: 1920, logical_height: 1080
	xdg_output_v1
		output: 46
		name: 'HDMI-A-1'
		description: 'Acer Technologies Acer G235H LJK0W0044322 (HDMI-A-1)'
		logical_x: 0, logical_y: 0
		logical_width: 1920, logical_height: 1080
	xdg_output_v1
		output: 45
		name: 'VGA-1'
		description: 'IMAGEQUEST Co., Ltd HDIT22W DSUB 1616116161616 (VGA-1)'
		logical_x: 3840, logical_y: 0
		logical_width: 1920, logical_height: 1080
interface: 'zwlr_output_manager_v1',                     version:  4, name: 22
interface: 'zwlr_input_inhibit_manager_v1',              version:  1, name: 23
interface: 'zwp_keyboard_shortcuts_inhibit_manager_v1',  version:  1, name: 24
interface: 'zext_workspace_manager_v1',                  version:  1, name: 25
interface: 'zwp_pointer_constraints_v1',                 version:  1, name: 26
interface: 'zwp_relative_pointer_manager_v1',            version:  1, name: 27
interface: 'zwp_virtual_keyboard_manager_v1',            version:  1, name: 28
interface: 'zwlr_virtual_pointer_manager_v1',            version:  2, name: 29
interface: 'zwlr_foreign_toplevel_manager_v1',           version:  3, name: 30
interface: 'wp_drm_lease_device_v1',                     version:  1, name: 31
interface: 'zwp_tablet_manager_v2',                      version:  1, name: 32
interface: 'zwp_idle_inhibit_manager_v1',                version:  1, name: 33
interface: 'zxdg_exporter_v1',                           version:  1, name: 34
interface: 'zxdg_importer_v1',                           version:  1, name: 35
interface: 'zxdg_exporter_v2',                           version:  1, name: 36
interface: 'zxdg_importer_v2',                           version:  1, name: 37
interface: 'zwp_pointer_gestures_v1',                    version:  3, name: 38
interface: 'zwp_text_input_manager_v3',                  version:  1, name: 39
interface: 'zwp_input_method_manager_v2',                version:  1, name: 40
interface: 'xdg_activation_v1',                          version:  1, name: 41
interface: 'xwayland_shell_v1',                          version:  1, name: 42
interface: 'hyprland_toplevel_export_manager_v1',        version:  2, name: 43
interface: 'wp_fractional_scale_manager_v1',             version:  1, name: 44
interface: 'wl_output',                                  version:  4, name: 45
	name: VGA-1
	description: IMAGEQUEST Co., Ltd HDIT22W DSUB 1616116161616 (VGA-1)
	x: 0, y: 0, scale: 1,
	physical_width: 480 mm, physical_height: 270 mm,
	make: 'IMAGEQUEST Co., Ltd', model: 'HDIT22W DSUB',
	subpixel_orientation: unknown, output_transform: normal,
	mode:
		width: 1920 px, height: 1080 px, refresh: 60.000 Hz,
		flags: current
interface: 'wl_output',                                  version:  4, name: 46
	name: HDMI-A-1
	description: Acer Technologies Acer G235H LJK0W0044322 (HDMI-A-1)
	x: 0, y: 0, scale: 1,
	physical_width: 510 mm, physical_height: 290 mm,
	make: 'Acer Technologies', model: 'Acer G235H',
	subpixel_orientation: unknown, output_transform: normal,
	mode:
		width: 1920 px, height: 1080 px, refresh: 60.000 Hz,
		flags: current
interface: 'wl_output',                                  version:  4, name: 47
	name: HDMI-A-2
	description: ASUSTek COMPUTER INC ASUS VA27EHE N2LMTF151742 (HDMI-A-2)
	x: 0, y: 0, scale: 1,
	physical_width: 600 mm, physical_height: 340 mm,
	make: 'ASUSTek COMPUTER INC', model: 'ASUS VA27EHE',
	subpixel_orientation: unknown, output_transform: normal,
	mode:
		width: 1920 px, height: 1080 px, refresh: 60.000 Hz,
		flags: current