Delete thread data at eglReleaseThread.

Bug 29279831

Change-Id: If5dbcb3e32e88d1e574d45d3368ed114fd4f85b7
Reviewed-on: https://swiftshader-review.googlesource.com/5581
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libEGL/libEGL.cpp b/src/OpenGL/libEGL/libEGL.cpp
index 4d8a169..a85d301 100644
--- a/src/OpenGL/libEGL/libEGL.cpp
+++ b/src/OpenGL/libEGL/libEGL.cpp
@@ -485,7 +485,7 @@
 {
 	TRACE("()");
 
-	eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE);
+	detachThread();
 
 	return success(EGL_TRUE);
 }
diff --git a/src/OpenGL/libEGL/main.cpp b/src/OpenGL/libEGL/main.cpp
index 2479b4e..4597165 100644
--- a/src/OpenGL/libEGL/main.cpp
+++ b/src/OpenGL/libEGL/main.cpp
@@ -62,7 +62,10 @@
 {
 	TRACE("()");
 
+	eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE);
+
 	delete (Current*)sw::Thread::getLocalStorage(currentTLS);
+	sw::Thread::setLocalStorage(currentTLS, nullptr);
 }
 
 CONSTRUCTOR void attachProcess()