From b6712e264a097d4eaab7d11222e9d4eaa4934836 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 27 Oct 2018 19:58:54 +0200 Subject: [PATCH] fix crash with Py3 when releasing memory buffer --- src/App/Document.cpp | 1 + src/App/DocumentObject.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index a87cc8bada..5e71cbdb63 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1293,6 +1293,7 @@ Document::~Document() // not to dec'ref the Python object any more. // But we must still invalidate the Python object because it doesn't need to be // destructed right now because the interpreter can own several references to it. + Base::PyGILStateLocker lock; Base::PyObjectBase* doc = (Base::PyObjectBase*)DocumentPythonObject.ptr(); // Call before decrementing the reference counter, otherwise a heap error can occur doc->setInvalid(); diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 2446931b3b..409f6220ce 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -63,6 +63,7 @@ DocumentObject::DocumentObject(void) DocumentObject::~DocumentObject(void) { if (!PythonObject.is(Py::_None())){ + Base::PyGILStateLocker lock; // Remark: The API of Py::Object has been changed to set whether the wrapper owns the passed // Python object or not. In the constructor we forced the wrapper to own the object so we need // not to dec'ref the Python object any more.