Skip to content

Commit 0e8fcc1

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 8d9877e commit 0e8fcc1

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

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

0 commit comments

Comments
 (0)