Skip to content

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

Open
@Eclips4

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and 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