From 93186e4999a8ed5c343a3a432dc5cdc5681628b7 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 5 Jan 2018 21:56:27 +0100 Subject: [PATCH] Wayland: Fix glfwTerminate segfault on failed init Closes #1172. --- src/wl_init.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/wl_init.c b/src/wl_init.c index 78d5901e..c8051902 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -775,15 +775,22 @@ void _glfwPlatformTerminate(void) _glfwTerminateJoysticksLinux(); #ifdef HAVE_XKBCOMMON_COMPOSE_H - xkb_compose_state_unref(_glfw.wl.xkb.composeState); + if (_glfw.wl.xkb.composeState) + xkb_compose_state_unref(_glfw.wl.xkb.composeState); #endif - xkb_keymap_unref(_glfw.wl.xkb.keymap); - xkb_state_unref(_glfw.wl.xkb.state); - xkb_context_unref(_glfw.wl.xkb.context); + if (_glfw.wl.xkb.keymap) + xkb_keymap_unref(_glfw.wl.xkb.keymap); + if (_glfw.wl.xkb.state) + xkb_state_unref(_glfw.wl.xkb.state); + if (_glfw.wl.xkb.context) + xkb_context_unref(_glfw.wl.xkb.context); - dlclose(_glfw.wl.xkb.handle); - _glfw.wl.xkb.handle = NULL; + if (_glfw.wl.xkb.handle) + { + _glfw_dlclose(_glfw.wl.xkb.handle); + _glfw.wl.xkb.handle = NULL; + } if (_glfw.wl.cursorTheme) wl_cursor_theme_destroy(_glfw.wl.cursorTheme);