Skip to content

Commit b1ddc3b

Browse files
committed
pyexpat: Add test for pytest memleak issue 140593
1 parent caae331 commit b1ddc3b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_pyexpat.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,24 @@ def test_expaterror(self):
718718
self.assertEqual(e.code,
719719
errors.codes[errors.XML_ERROR_UNCLOSED_TOKEN])
720720

721+
class ElementDeclHandlerCleanUpLeakTest(unittest.TestCase):
722+
723+
def test_trigger_leak(self):
724+
# Unfixed, this test would leak 32 to 56 bytes of memory
725+
# https://github.com/python/cpython/issues/140593
726+
data = textwrap.dedent('''\
727+
<!DOCTYPE quotations SYSTEM "quotations.dtd" [
728+
<!ELEMENT root ANY>
729+
]>
730+
<root/>
731+
''').encode('UTF-8')
732+
733+
parser = expat.ParserCreate()
734+
parser.NotStandaloneHandler = lambda: 1.234 # arbitrary float
735+
parser.ElementDeclHandler = lambda _1, _2: None
736+
with self.assertRaises(TypeError):
737+
parser.Parse(data, True)
738+
721739

722740
class ForeignDTDTests(unittest.TestCase):
723741
"""

0 commit comments

Comments
 (0)