Skip to content

Commit e5badfb

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.
1 parent 003b720 commit e5badfb

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
@@ -118,7 +118,9 @@ static void PythonQtInstanceWrapper_deleteObject(PythonQtInstanceWrapper* self,
118118

119119
static void PythonQtInstanceWrapper_dealloc(PythonQtInstanceWrapper* self)
120120
{
121-
PythonQtInstanceWrapper_deleteObject(self);
121+
if (PythonQt::self()) {
122+
PythonQtInstanceWrapper_deleteObject(self);
123+
}
122124
self->_obj.~QPointer<QObject>();
123125
Py_TYPE(self)->tp_free((PyObject*)self);
124126
}

0 commit comments

Comments
 (0)