mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
bpo-31095: fix potential crash during GC (GH-2974)
This commit is contained in:
parent
bf9075a0c5
commit
a6296d34a4
14 changed files with 60 additions and 13 deletions
|
@ -627,6 +627,7 @@ element_gc_clear(ElementObject *self)
|
|||
static void
|
||||
element_dealloc(ElementObject* self)
|
||||
{
|
||||
/* bpo-31095: UnTrack is needed before calling any callbacks */
|
||||
PyObject_GC_UnTrack(self);
|
||||
Py_TRASHCAN_SAFE_BEGIN(self)
|
||||
|
||||
|
@ -2076,6 +2077,8 @@ elementiter_dealloc(ElementIterObject *it)
|
|||
{
|
||||
Py_ssize_t i = it->parent_stack_used;
|
||||
it->parent_stack_used = 0;
|
||||
/* bpo-31095: UnTrack is needed before calling any callbacks */
|
||||
PyObject_GC_UnTrack(it);
|
||||
while (i--)
|
||||
Py_XDECREF(it->parent_stack[i].parent);
|
||||
PyMem_Free(it->parent_stack);
|
||||
|
@ -2083,7 +2086,6 @@ elementiter_dealloc(ElementIterObject *it)
|
|||
Py_XDECREF(it->sought_tag);
|
||||
Py_XDECREF(it->root_element);
|
||||
|
||||
PyObject_GC_UnTrack(it);
|
||||
PyObject_GC_Del(it);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue