GeezerVison is showing github.com — gh-146527: Fix memory leak in _PyGC_Fini() by vstinner · Pull Request #150969 · python/cpython
Conversation
vstinner
commented
Jun 5, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Free generation_stats allocated by _PyGC_Init().
Fix Python/gc.c: Python/gc_free_threading.c was already fixed.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Free generation_stats allocated by _PyGC_Init().
Fix Python/gc.c: Python/gc_free_threading.c was already fixed.
|
For example, the leak can be seen with Valgrind.
$ PYTHONMALLOC=malloc valgrind --leak-check=full --show-leak-kinds=all --num-callers=20 ./python -c pass
(...)
==3201846== HEAP SUMMARY:
==3201846== in use at exit: 1,112 bytes in 1 blocks
==3201846== total heap usage: 28,765 allocs, 28,764 frees, 6,620,982 bytes allocated
==3201846==
==3201846== 1,112 bytes in 1 blocks are still reachable in loss record 1 of 1
==3201846== at 0x484862B: calloc (vg_replace_malloc.c:1616)
==3201846== by 0x4FE115: _PyMem_RawCalloc (obmalloc.c:80)
==3201846== by 0x511FC1: PyMem_RawCalloc (obmalloc.c:1222)
==3201846== by 0x62A744: _PyGC_Init (gc.c:137)
==3201846== by 0x65DB65: pycore_interp_init (pylifecycle.c:975)
==3201846== by 0x65DD71: pyinit_config (pylifecycle.c:1040)
==3201846== by 0x666D3A: pyinit_core (pylifecycle.c:1203)
==3201846== by 0x666E13: Py_InitializeFromConfig (pylifecycle.c:1631)
==3201846== by 0x69888E: pymain_init (main.c:69)
==3201846== by 0x698953: pymain_main (main.c:817)
==3201846== by 0x6989E4: Py_BytesMain (main.c:850)
==3201846== by 0x401CEE: main (python.c:15)
==3201846==
==3201846== LEAK SUMMARY:
==3201846== definitely lost: 0 bytes in 0 blocks
==3201846== indirectly lost: 0 bytes in 0 blocks
==3201846== possibly lost: 0 bytes in 0 blocks
==3201846== still reachable: 1,112 bytes in 1 blocks
==3201846== suppressed: 0 bytes in 0 blocks
(...)
I found the leak when building Python with ASAN.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
vstinner reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
added a commit
that referenced
this pull request
Jun 5, 2026
gh-146527: Fix memory leak in _PyGC_Fini() (GH-150969)
Free generation_stats allocated by _PyGC_Init().
Fix Python/gc.c: Python/gc_free_threading.c was already fixed.
(cherry picked from commit 0036565)
Co-authored-by: Victor Stinner <[email protected]>
vstinner reacted with hooray emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
philthompson10
pushed a commit
to philthompson10/cpython
that referenced
this pull request
Jun 17, 2026
Free generation_stats allocated by _PyGC_Init().
Fix Python/gc.c: Python/gc_free_threading.c was already fixed.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|