mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
bpo-31499, xml.etree: Fix xmlparser_gc_clear() crash (#3641)
* bpo-31499, xml.etree: Fix xmlparser_gc_clear() crash xml.etree: xmlparser_gc_clear() now sets self.parser to NULL to prevent a crash in xmlparser_dealloc() if xmlparser_gc_clear() was called previously by the garbage collector, because the parser was part of a reference cycle. Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
9b47af6537
commit
e727d41ffc
3 changed files with 26 additions and 1 deletions
|
|
@ -65,6 +65,26 @@ class MiscTests(unittest.TestCase):
|
|||
del root
|
||||
support.gc_collect()
|
||||
|
||||
def test_parser_ref_cycle(self):
|
||||
# bpo-31499: xmlparser_dealloc() crashed with a segmentation fault when
|
||||
# xmlparser_gc_clear() was called previously by the garbage collector,
|
||||
# when the parser was part of a reference cycle.
|
||||
|
||||
def parser_ref_cycle():
|
||||
parser = cET.XMLParser()
|
||||
# Create a reference cycle using an exception to keep the frame
|
||||
# alive, so the parser will be destroyed by the garbage collector
|
||||
try:
|
||||
raise ValueError
|
||||
except ValueError as exc:
|
||||
err = exc
|
||||
|
||||
# Create a parser part of reference cycle
|
||||
parser_ref_cycle()
|
||||
# Trigger an explicit garbage collection to break the reference cycle
|
||||
# and so destroy the parser
|
||||
support.gc_collect()
|
||||
|
||||
|
||||
@unittest.skipUnless(cET, 'requires _elementtree')
|
||||
class TestAliasWorking(unittest.TestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue