Skip to content

Commit 83f67ae

Browse files
msmolensjcfr
authored andcommitted
Prevent crash when an object is destroyed after calling PythonQt::cleanup()
In certain situations the dealloc callback `PythonQtInstanceWrapper_dealloc` is called after `PythonQt::cleanup()` has been run. This can happen when Python destroys objects during `Py_Finalize()`. This commit adds a check that PythonQt is still initialized in the dealloc callback. (cherry picked from commit commontk/PythonQt@e4bd663)
1 parent 34eaa2c commit 83f67ae

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/PythonQtInstanceWrapper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ static void PythonQtInstanceWrapper_deleteObject(PythonQtInstanceWrapper* self,
127127

128128
static void PythonQtInstanceWrapper_dealloc(PythonQtInstanceWrapper* self)
129129
{
130-
PythonQtInstanceWrapper_deleteObject(self);
130+
if (PythonQt::self()) {
131+
PythonQtInstanceWrapper_deleteObject(self);
132+
}
131133
self->_obj.~QPointer<QObject>();
132134
Py_TYPE(self)->tp_free((PyObject*)self);
133135
}

0 commit comments

Comments
 (0)