Fix deletion of uninitialized POSIX TLS key

Zero (the initial value of context) is a valid TLS key, so doing this
can delete someone else's key.

Fixes #627.
master
Roman Donchenko ago%!(EXTRA string=10 years) committed by Camilla Berglund
parent 43f4afef78
commit cdf08c1ff3
  1. 4
      src/posix_tls.c
  2. 1
      src/posix_tls.h

@ -41,12 +41,14 @@ int _glfwCreateContextTLS(void)
return GLFW_FALSE; return GLFW_FALSE;
} }
_glfw.posix_tls.allocated = GLFW_TRUE;
return GLFW_TRUE; return GLFW_TRUE;
} }
void _glfwDestroyContextTLS(void) void _glfwDestroyContextTLS(void)
{ {
pthread_key_delete(_glfw.posix_tls.context); if (_glfw.posix_tls.allocated)
pthread_key_delete(_glfw.posix_tls.context);
} }
void _glfwSetContextTLS(_GLFWwindow* context) void _glfwSetContextTLS(_GLFWwindow* context)

@ -37,6 +37,7 @@
// //
typedef struct _GLFWtlsPOSIX typedef struct _GLFWtlsPOSIX
{ {
GLFWbool allocated;
pthread_key_t context; pthread_key_t context;
} _GLFWtlsPOSIX; } _GLFWtlsPOSIX;

Loading…
Cancel
Save