File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111 fresh = ['_elementtree' , 'xml.etree' ])
1212
1313
14+ @unittest .skipUnless (cET , 'requires _elementtree' )
1415class MiscTests (unittest .TestCase ):
1516 # Issue #8651.
1617 @support .bigmemtest (size = support ._2G + 100 , memuse = 1 , dry_run = False )
@@ -54,6 +55,15 @@ def test_del_attribute(self):
5455 del element .attrib
5556 self .assertEqual (element .attrib , {'A' : 'B' , 'C' : 'D' })
5657
58+ def test_trashcan (self ):
59+ # If this test fails, it will most likely die via segfault.
60+ e = root = cET .Element ('root' )
61+ for i in range (200000 ):
62+ e = cET .SubElement (e , 'x' )
63+ del e
64+ del root
65+ support .gc_collect ()
66+
5767
5868@unittest .skipUnless (cET , 'requires _elementtree' )
5969class TestAliasWorking (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -205,6 +205,8 @@ Core and Builtins
205205Library
206206-------
207207
208+ - Issue #28871: Fixed a crash when deallocate deep ElementTree.
209+
208210- Issue #19542: Fix bugs in WeakValueDictionary.setdefault() and
209211 WeakValueDictionary.pop() when a GC collection happens in another
210212 thread.
Original file line number Diff line number Diff line change @@ -626,6 +626,7 @@ static void
626626element_dealloc (ElementObject * self )
627627{
628628 PyObject_GC_UnTrack (self );
629+ Py_TRASHCAN_SAFE_BEGIN (self )
629630
630631 if (self -> weakreflist != NULL)
631632 PyObject_ClearWeakRefs ((PyObject * ) self );
@@ -636,6 +637,7 @@ element_dealloc(ElementObject* self)
636637
637638 RELEASE (sizeof (ElementObject ), "destroy element ");
638639 Py_TYPE (self )- > tp_free ((PyObject * )self );
640+ Py_TRASHCAN_SAFE_END (self )
639641}
640642
641643/* -------------------------------------------------------------------- */
You can’t perform that action at this time.
0 commit comments