From c710d2c05d4e62e408f73116f00978319c22de2b 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. This was adapted to 3.3-stable from 4e8c4901e9985765a3951423ff9174459339a62b. --- README.md | 1 + src/wl_init.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a23d146b..ed88f277 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ information on what to include when reporting a bug. ## Changelog + - [Wayland] Bugfix: Terminating the library before showing a window could segfault - [Linux] Bugfix: `regfree´ was called on invalid data (#2464) diff --git a/src/wl_init.c b/src/wl_init.c index bc786677..f66c63a7 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -637,10 +637,15 @@ void _glfwPlatformTerminate(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) + _glfwPlatformWaitEvents(); + libdecor_unref(_glfw.wl.libdecor.context); + } if (_glfw.wl.libdecor.handle) {