Skip to content

Segmentation fault when frequently creating and removing references in XML tree  #4860

@xiaxinmeng

Description

@xiaxinmeng

This code generates an XML tree structure with 20001 nested elements, where each element is named 'x'. Initially, a root element named 'x' is created using xml.etree.cElementTree. Then, the for loop creates 20000 sub-elements of the root element. Each sub-element is also named 'x' and is created using the SubElement method. The variable y is assigned the last sub-element created. It is a reference to the deepest nested element in the tree. Finally, the variable x is deleted, which removes the reference to the root element. However, the y variable still holds the reference to the entire XML tree structure, including the root element and all of its sub-elements.

test.py

import xml.etree.cElementTree as ElementTree
y = x = ElementTree.Element('x')
for i in range(20000): 
    y = ElementTree.SubElement(y, 'x')
del x

Crash message:
Segmentation fault (core dumped)

Environment:
Ubuntu 18.04
rustpython v0.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions