Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-117142: ctypes: Fix memory leak of StgInfo #118139

Closed
wants to merge 14 commits into from
Closed

gh-117142: ctypes: Fix memory leak of StgInfo #118139

wants to merge 14 commits into from

Conversation

neonene
Copy link
Contributor

@neonene neonene commented Apr 22, 2024

Fix intentional memory leak during a finish by introducing _PyType_GetBaseBySpec() with a type slot ID.

Discussion: encukou/abi3#19

>python_d -X showrefcount -c "import ctypes"
[188 refs, 132 blocks]  # before
[0 refs, 0 blocks]      # after

cc @encukou

@encukou
Copy link
Member

encukou commented Apr 23, 2024

All metaclasses defined by _ctypes derive from PyCType_Type. So, if there are mro entries with the right ModuleDef, the last one is PyCType_Type.

@neonene

This comment was marked as outdated.

@encukou
Copy link
Member

encukou commented May 22, 2024

Thank you for working on this. It clearly shows we need better APIs to handle type/module teardown correctly in general.
For a stdlib module, in 3.13, we can use implementation details for a less invasive fix: #119424.

@encukou encukou closed this May 22, 2024
@neonene neonene deleted the basespec branch May 22, 2024 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants