Skip to content

_elementtree.XMLParser can leak references if __init__ method called on instance #114795

Open

Description

@Eclips4

Bug report

Bug description:

Reproducer:

import _elementtree as ET

a = ET.XMLParser()
a.__init__()

current main branch:

./python.exe -X showrefcount example.py                                   
[8736 refs, 5267 blocks]

3.12 branch:

./python.exe -X showrefcount example.py
[8327 refs, 4977 blocks]

3.11 branch:

./python.exe -X showrefcount example.py
[1557 refs, 575 blocks]

The number of leaks increases if we call __init__ multiple times (current main branch):
Code:

import _elementtree as ET

a = ET.XMLParser()
a.__init__()
a.__init__()
a.__init__()
a.__init__()
a.__init__()
a.__init__()
a.__init__()
./python.exe -X showrefcount example.py
[8838 refs, 5357 blocks]

I doesn't sure, is this worth to fix? This is pure python code, so in my opinion we should fix it.

CPython versions tested on:

3.11, 3.12, CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.11only security fixes
    3.12only security fixes
    3.13only security fixes
    on Jan 31, 2024
  2. serhiy-storchaka commented on Feb 2, 2024

    @serhiy-storchaka
    Member

    There was a similar issue #75939.

  3. added a commit that references this issue on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions