From 4e8c4901e9985765a3951423ff9174459339a62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 3 Jan 2024 18:01:29 +0100 Subject: [PATCH] Wayland: Fix segfault on termination A segfault could occur during termination if libdecor was found but no windows were created between initialization and termination. The wait for libdecor to finish its initialization was only performed before window creation, not at termination. Regression introduced by 9fdc425931888ea70bc095e53cc006fca8ccb703. --- src/wl_init.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wl_init.c b/src/wl_init.c index 0ec65900..fd6b7e9c 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -846,10 +846,15 @@ void _glfwTerminateWayland(void) _glfwTerminateEGL(); _glfwTerminateOSMesa(); - if (_glfw.wl.libdecor.callback) - wl_callback_destroy(_glfw.wl.libdecor.callback); if (_glfw.wl.libdecor.context) + { + // Allow libdecor to finish receiving all its requested globals + // and ensure the associated sync callback object is destroyed + while (!_glfw.wl.libdecor.ready) + _glfwWaitEventsWayland(); + libdecor_unref(_glfw.wl.libdecor.context); + } if (_glfw.wl.libdecor.handle) {