mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-35008: Fix possible leaks in Element.__setstate__(). (GH-9924)
C implementation of xml.etree.ElementTree.Element.__setstate__() leaked references to children when called for already initialized element.
This commit is contained in:
parent
9d4712bc8f
commit
6f906b3d72
3 changed files with 83 additions and 31 deletions
|
@ -117,6 +117,22 @@ class MiscTests(unittest.TestCase):
|
|||
elem.tail = X()
|
||||
elem.__setstate__({'tag': 42}) # shouldn't cause an assertion failure
|
||||
|
||||
def test_setstate_leaks(self):
|
||||
# Test reference leaks
|
||||
elem = cET.Element.__new__(cET.Element)
|
||||
for i in range(100):
|
||||
elem.__setstate__({'tag': 'foo', 'attrib': {'bar': 42},
|
||||
'_children': [cET.Element('child')],
|
||||
'text': 'text goes here',
|
||||
'tail': 'opposite of head'})
|
||||
|
||||
self.assertEqual(elem.tag, 'foo')
|
||||
self.assertEqual(elem.text, 'text goes here')
|
||||
self.assertEqual(elem.tail, 'opposite of head')
|
||||
self.assertEqual(list(elem.attrib.items()), [('bar', 42)])
|
||||
self.assertEqual(len(elem), 1)
|
||||
self.assertEqual(elem[0].tag, 'child')
|
||||
|
||||
|
||||
@unittest.skipUnless(cET, 'requires _elementtree')
|
||||
class TestAliasWorking(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue