Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix use-after-free when :meth:`~object.__del__` changes the base class. Patch by
Sergey Miryanov.
8 changes: 4 additions & 4 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,13 @@ PyObject_CallFinalizer(PyObject *self)
if (tp->tp_finalize == NULL)
return;
/* tp_finalize should only be called once. */
if (_PyType_IS_GC(tp) && _PyGC_FINALIZED(self))
return;

tp->tp_finalize(self);
if (_PyType_IS_GC(tp)) {
if (_PyGC_FINALIZED(self))
return;

_PyGC_SET_FINALIZED(self);
}
tp->tp_finalize(self);
}

int
Expand Down
4 changes: 4 additions & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2771,6 +2771,10 @@ subtype_dealloc(PyObject *self)
}
_PyObject_GC_UNTRACK(self);
}

/* Extract the type again; tp_finalize may have changed it */
type = Py_TYPE(self);

/*
If we added a weaklist, we clear it. Do this *before* calling tp_del,
clearing slots, or clearing the instance dict.
Expand Down
Loading