瀏覽代碼

HPCC-21207 Python 3 examples segfault at termination

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 6 年之前
父節點
當前提交
7efbc16bd0
共有 2 個文件被更改,包括 22 次插入21 次删除
  1. 12 21
      plugins/py3embed/py3embed.cpp
  2. 10 0
      plugins/pyembed/pyembed.cpp

+ 12 - 21
plugins/py3embed/py3embed.cpp

@@ -308,6 +308,15 @@ public:
             if (pythonLibrary)
                 FreeSharedObject(pythonLibrary);
         }
+        else
+        {
+            // Need to avoid releasing the associated py objects when these members destructors are called.
+            namedtuple.getClear();
+            namedtupleTypes.getClear();
+            compiledScripts.getClear();
+            preservedScopes.getClear();
+
+        }
     }
     bool isInitialized()
     {
@@ -516,28 +525,10 @@ MODULE_INIT(INIT_PRIORITY_STANDARD)
         }
     }
 #else
-    FILE *diskfp = fopen("/proc/self/maps", "r");
-    if (diskfp)
+    StringBuffer modname;
+    if (findLoadedModule(modname, "libpy3embed"))
     {
-        char ln[_MAX_PATH];
-        while (fgets(ln, sizeof(ln), diskfp))
-        {
-            if (strstr(ln, "libpy3embed"))
-            {
-                const char *fullName = strchr(ln, '/');
-                if (fullName)
-                {
-                    char *tail = (char *) strstr(fullName, SharedObjectExtension);
-                    if (tail)
-                    {
-                        tail[strlen(SharedObjectExtension)] = 0;
-                        keepLoadedHandle = LoadSharedObject(fullName, false, false);
-                        break;
-                    }
-                }
-            }
-        }
-        fclose(diskfp);
+        keepLoadedHandle = LoadSharedObject(modname, false, false);
     }
 #endif
     return true;

+ 10 - 0
plugins/pyembed/pyembed.cpp

@@ -28,6 +28,7 @@
 #include "platform.h"
 #include "frameobject.h"
 #include "jexcept.hpp"
+#include "jutil.hpp"
 #include "jthread.hpp"
 #include "jregexp.hpp"
 #include "hqlplugins.hpp"
@@ -301,6 +302,15 @@ public:
             if (pythonLibrary)
                 FreeSharedObject(pythonLibrary);
         }
+        else
+        {
+            // Need to avoid releasing the associated py objects when these members destructors are called.
+            namedtuple.getClear();
+            namedtupleTypes.getClear();
+            compiledScripts.getClear();
+            preservedScopes.getClear();
+
+        }
     }
     bool isInitialized()
     {