From f75276ba5cda4fe26bd1658504790b101c6ac3e3 Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Fri, 8 May 2015 02:28:33 +0000
Subject: [PATCH] glslang tear down: Include deleting the keyword map in tear
 down.  From johnk and sawato shusaku (shusaku.sawato@dmprof.com).

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31115 e7fa87d3-cd2b-0410-9028-fcbf551c1848
---
 OGLCompilersDLL/InitializeDll.cpp         | 44 +++++++++++------------
 glslang/MachineIndependent/Scan.cpp       |  8 +++++
 glslang/MachineIndependent/ScanContext.h  |  2 ++
 glslang/MachineIndependent/ShaderLang.cpp |  4 ++-
 4 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/OGLCompilersDLL/InitializeDll.cpp b/OGLCompilersDLL/InitializeDll.cpp
index 9e8124bf8..049ee3ebc 100644
--- a/OGLCompilersDLL/InitializeDll.cpp
+++ b/OGLCompilersDLL/InitializeDll.cpp
@@ -50,13 +50,13 @@ bool InitProcess()
     glslang::GetGlobalLock();
 
     if (ThreadInitializeIndex != OS_INVALID_TLS_INDEX) {
-		//
-		// Function is re-entrant.
-		//
+        //
+        // Function is re-entrant.
+        //
 
         glslang::ReleaseGlobalLock();
         return true;
-	}
+    }
 
     ThreadInitializeIndex = OS_AllocTLSIndex();
 
@@ -65,16 +65,16 @@ bool InitProcess()
 
         glslang::ReleaseGlobalLock();
         return false;
-	}
+    }
 
     if (! InitializePoolIndex()) {
         assert(0 && "InitProcess(): Failed to initialize global pool");
 
         glslang::ReleaseGlobalLock();
         return false;
-	}
+    }
 
-	InitThread();
+    InitThread();
 
     glslang::ReleaseGlobalLock();
     return true;
@@ -83,23 +83,23 @@ bool InitProcess()
 
 bool InitThread()
 {
-	//
+    //
     // This function is re-entrant
-	//
+    //
     if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX) {
-		assert(0 && "InitThread(): Process hasn't been initalised.");
+        assert(0 && "InitThread(): Process hasn't been initalised.");
         return false;
-	}
+    }
 
     if (OS_GetTLSValue(ThreadInitializeIndex) != 0)
         return true;
 
-	InitializeMemoryPools();
+    InitializeMemoryPools();
 
     if (! OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {
-		assert(0 && "InitThread(): Unable to set init flag.");
+        assert(0 && "InitThread(): Unable to set init flag.");
         return false;
-	}
+    }
 
     return true;
 }
@@ -112,18 +112,18 @@ bool DetachThread()
     if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
         return true;
 
-	//
-	// Function is re-entrant and this thread may not have been initalised.
-	//
+    //
+    // Function is re-entrant and this thread may not have been initialized.
+    //
     if (OS_GetTLSValue(ThreadInitializeIndex) != 0) {
         if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)0)) {
-			assert(0 && "DetachThread(): Unable to clear init flag.");
+            assert(0 && "DetachThread(): Unable to clear init flag.");
             success = false;
-		}
+        }
 
-		FreeGlobalPools();
+        FreeGlobalPools();
 
-	}
+    }
 
     return success;
 }
@@ -139,7 +139,7 @@ bool DetachProcess()
 
     success = DetachThread();
 
-	FreePoolIndex();
+    FreePoolIndex();
 
     OS_FreeTLSIndex(ThreadInitializeIndex);
     ThreadInitializeIndex = OS_INVALID_TLS_INDEX;
diff --git a/glslang/MachineIndependent/Scan.cpp b/glslang/MachineIndependent/Scan.cpp
index a77d39287..55ebcea82 100644
--- a/glslang/MachineIndependent/Scan.cpp
+++ b/glslang/MachineIndependent/Scan.cpp
@@ -514,6 +514,14 @@ void TScanContext::fillInKeywordMap()
     ReservedSet->insert("using");
 }
 
+void TScanContext::deleteKeywordMap()
+{
+    delete KeywordMap;
+    KeywordMap = 0;
+    delete ReservedSet;
+    ReservedSet = 0;
+}
+
 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
 {
     do {
diff --git a/glslang/MachineIndependent/ScanContext.h b/glslang/MachineIndependent/ScanContext.h
index bb8c42bbb..621c771d9 100644
--- a/glslang/MachineIndependent/ScanContext.h
+++ b/glslang/MachineIndependent/ScanContext.h
@@ -52,6 +52,8 @@ public:
     virtual ~TScanContext() { }
 
     static void fillInKeywordMap();
+    static void deleteKeywordMap();
+
     int tokenize(TPpContext*, TParserToken&);
 
 protected:
diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp
index d70263f74..9178df2a1 100644
--- a/glslang/MachineIndependent/ShaderLang.cpp
+++ b/glslang/MachineIndependent/ShaderLang.cpp
@@ -583,7 +583,7 @@ int ShInitialize()
 
     if (! PerProcessGPA)
         PerProcessGPA = new TPoolAllocator();
-    
+
     glslang::TScanContext::fillInKeywordMap();
 
     return 1;
@@ -668,6 +668,8 @@ int __fastcall ShFinalize()
         PerProcessGPA = 0;
     }
 
+    glslang::TScanContext::deleteKeywordMap();
+
     return 1;
 }
 
-- 
GitLab