Pārlūkot izejas kodu

Merge pull request #3928 from richardkchapman/embed-core

HPCC-8732 Core on second embedded javascript query in Roxie

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 12 gadi atpakaļ
vecāks
revīzija
3a03dcecc5

+ 8 - 2
plugins/javaembed/javaembed.cpp

@@ -915,10 +915,16 @@ static __thread ThreadTermFunc threadHookChain;
 
 static void releaseContext()
 {
-    delete threadContext;
-    threadContext = NULL;
+    if (threadContext)
+    {
+        delete threadContext;
+        threadContext = NULL;
+    }
     if (threadHookChain)
+    {
         (*threadHookChain)();
+        threadHookChain = NULL;
+    }
 }
 
 class JavaEmbedContext : public CInterfaceOf<IEmbedContext>

+ 8 - 2
plugins/pyembed/pyembed.cpp

@@ -226,10 +226,16 @@ static __thread ThreadTermFunc threadHookChain;
 
 static void releaseContext()
 {
-    delete threadContext;
-    threadContext = NULL;
+    if (threadContext)
+    {
+        delete threadContext;
+        threadContext = NULL;
+    }
     if (threadHookChain)
+    {
         (*threadHookChain)();
+        threadHookChain = NULL;
+    }
 }
 
 // Use a global object to ensure that the Python interpreter is initialized on main thread

+ 8 - 1
plugins/v8embed/v8embed.cpp

@@ -481,9 +481,16 @@ static __thread ThreadTermFunc threadHookChain;
 
 static void releaseContext()
 {
-    ::Release(theFunctionContext);
+    if (theFunctionContext)
+    {
+        ::Release(theFunctionContext);
+        theFunctionContext = NULL;
+    }
     if (threadHookChain)
+    {
         (*threadHookChain)();
+        threadHookChain = NULL;
+    }
 }
 
 class V8JavascriptEmbedContext : public CInterfaceOf<IEmbedContext>

+ 6 - 0
system/jlib/jthread.cpp

@@ -267,7 +267,10 @@ int Thread::begin()
     }
 #endif
     if (threadTerminationHook)
+    {
         (*threadTerminationHook)();
+        threadTerminationHook = NULL;
+    }
 #ifdef _WIN32
 #ifndef _DEBUG
     CloseHandle(hThread);   // leak handle when debugging, 
@@ -809,7 +812,10 @@ public:
             }
 #endif
             if (threadTerminationHook)
+            {
                 (*threadTerminationHook)();    // Reset any pre-thread state.
+                threadTerminationHook = NULL;
+            }
         } while (parent.notifyStopped(this));
         return 0;
     }