Skip to content

Commit 1fa438b

Browse files
msmolensjamesobutler
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 4f48e39 commit 1fa438b

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)