From 7b6985f033c0c0d272a0a398a1e8f572361d791f Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Wed, 28 Oct 2015 15:22:33 +0300 Subject: [PATCH] Don't delete the POSIX TLS key if it hasn't been created yet 0 (the initial value of context) is a valid TLS key, so doing this can delete someone else's key. --- src/posix_tls.c | 7 ++++++- src/posix_tls.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/posix_tls.c b/src/posix_tls.c index b38367447..2cb4d3576 100644 --- a/src/posix_tls.c +++ b/src/posix_tls.c @@ -41,12 +41,17 @@ int _glfwCreateContextTLS(void) return GLFW_FALSE; } + _glfw.posix_tls.allocated = GLFW_TRUE; return GLFW_TRUE; } void _glfwDestroyContextTLS(void) { - pthread_key_delete(_glfw.posix_tls.context); + if (_glfw.posix_tls.allocated) + { + pthread_key_delete(_glfw.posix_tls.context); + _glfw.posix_tls.allocated = GLFW_FALSE; + } } void _glfwSetContextTLS(_GLFWwindow* context) diff --git a/src/posix_tls.h b/src/posix_tls.h index c653aad12..124f2145e 100644 --- a/src/posix_tls.h +++ b/src/posix_tls.h @@ -37,6 +37,7 @@ // typedef struct _GLFWtlsPOSIX { + GLFWbool allocated; pthread_key_t context; } _GLFWtlsPOSIX;