mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-140593: Fix a memory leak in function my_ElementDeclHandler of pyexpat (#140602)
Ensure that the memory allocated for the content model passed to `my_ElementDeclHandler` is freed in all error paths.
This commit is contained in:
parent
37827c1752
commit
e34a5e3304
3 changed files with 21 additions and 1 deletions
|
|
@ -684,6 +684,23 @@ def test_change_size_2(self):
|
|||
parser.Parse(xml2, True)
|
||||
self.assertEqual(self.n, 4)
|
||||
|
||||
class ElementDeclHandlerTest(unittest.TestCase):
|
||||
def test_trigger_leak(self):
|
||||
# Unfixed, this test would leak the memory of the so-called
|
||||
# "content model" in function ``my_ElementDeclHandler`` of pyexpat.
|
||||
# See https://github.com/python/cpython/issues/140593.
|
||||
data = textwrap.dedent('''\
|
||||
<!DOCTYPE quotations SYSTEM "quotations.dtd" [
|
||||
<!ELEMENT root ANY>
|
||||
]>
|
||||
<root/>
|
||||
''').encode('UTF-8')
|
||||
|
||||
parser = expat.ParserCreate()
|
||||
parser.NotStandaloneHandler = lambda: 1.234 # arbitrary float
|
||||
parser.ElementDeclHandler = lambda _1, _2: None
|
||||
self.assertRaises(TypeError, parser.Parse, data, True)
|
||||
|
||||
class MalformedInputTest(unittest.TestCase):
|
||||
def test1(self):
|
||||
xml = b"\0\r\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue