Skip to content

gh-114795: Fix Element re-init memory leak in the C accelerator - #153538

Open
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:elementtree-reinit-extra-leak
Open

tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:elementtree-reinit-extra-leak

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Element.__init__ in the C accelerator leaked the element's previous children and attributes when called more than once, because create_extra allocated a new extra without freeing the old one. Clear it first, so re-initialization now discards the previous children and attributes like the pure-Python implementation.

element_init allocated a new extra without releasing the previous one,
leaking the element's children and attributes on a second __init__ call.
Clear the old extra first, so re-init discards the previous children and
attributes, matching the pure-Python implementation.
@serhiy-storchaka serhiy-storchaka changed the title gh-153537: Fix Element re-init memory leak in the C accelerator gh-114795: Fix Element re-init memory leak in the C accelerator Aug 17, 2026
Comment thread Modules/_elementtree.c Resolved
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Nov 17, 2026
Build the replacement state before releasing the previous state. This keeps destructor callbacks from leaving a partially updated element when they reenter Element.__init__.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants