Fix error freeing bpy_struct sub-classes WITH_PYTHON_SECURITY enabled

Python's behavior changed since this feature was added causing the
object to be tracked when freed by Python's subtype_dealloc even
if Blender has not tracked the data. Detect this case and untrack
the object before freeing.
This commit is contained in:
Campbell Barton 2024-03-12 16:37:36 +11:00
parent 658ef7c730
commit 1fa2a1a74d
1 changed files with 8 additions and 0 deletions

View File

@ -1173,6 +1173,14 @@ static void pyrna_struct_dealloc(BPy_StructRNA *self)
PyObject_GC_UnTrack(self);
pyrna_struct_clear(self);
}
else {
PyTypeObject *base = Py_TYPE(self)->tp_base;
/* Python temporarily tracks these types when freeing, see Python bug 26617. */
if (base && PyType_IS_GC(base)) {
PyObject_GC_UnTrack(self);
}
BLI_assert(!PyObject_GC_IsTracked((PyObject *)self));
}
#endif /* !USE_PYRNA_STRUCT_REFERENCE */
/* NOTE: for subclassed PyObjects calling PyObject_DEL() directly crashes. */