Skip to content

Use stackless traversal for tree destruction to avoid stack overflow#702

Merged
zeux merged 2 commits intomasterfrom
destroy-node-stackless
Apr 14, 2026
Merged

Use stackless traversal for tree destruction to avoid stack overflow#702
zeux merged 2 commits intomasterfrom
destroy-node-stackless

Conversation

@zeux
Copy link
Copy Markdown
Owner

@zeux zeux commented Apr 13, 2026

For very deep trees that can be parsed using our stackless parser,
attempts to remove the relevant nodes may cause a stack overflow due to
deep recursion.

Instead, use a stackless traversal; this is a little different from
other traversals we already have in the library, as it needs to process
each node after the entire subtree to avoid accessing destroyed
memory.

Fixes #701.

zeux added 2 commits April 13, 2026 10:04
For very deep trees that can be parsed using our stackless parser,
attempts to remove the relevant nodes may cause a stack overflow due to
deep recursion.

Instead, use a stackless traversal; this is a little different from
other traversals we already have in the library, as it needs to process
each node *after* the entire subtree to avoid accessing destroyed
memory.

This is part of a new destroy_tree function; destroy_node now only
destroys the node's attributes/name/value.
This would have previously failed in some configurations due to a
recursive implementation.
@zeux zeux merged commit 058733a into master Apr 14, 2026
24 checks passed
@zeux zeux deleted the destroy-node-stackless branch April 14, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack overflow in destroy_node() via remove_child()/remove_children() on deeply nested XML

1 participant