https://github.com/python/cpython/commit/06ffcde725c6ee30c4717bd2c2375f6019d172c1
commit: 06ffcde725c6ee30c4717bd2c2375f6019d172c1
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-06-05T14:11:37Z
summary:

[3.15] gh-146527: Fix memory leak in _PyGC_Fini() (GH-150969) (#150970)

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 0036565e81b9580d645862bcc6249e2ae4f1fd03)

Co-authored-by: Victor Stinner <[email protected]>

files:
M Python/gc.c

diff --git a/Python/gc.c b/Python/gc.c
index 54ac1b089e503d..201c621bcc3cb9 100644
--- a/Python/gc.c
+++ b/Python/gc.c
@@ -1876,6 +1876,8 @@ _PyGC_Fini(PyInterpreterState *interp)
     GCState *gcstate = &interp->gc;
     Py_CLEAR(gcstate->garbage);
     Py_CLEAR(gcstate->callbacks);
+    PyMem_RawFree(gcstate->generation_stats);
+    gcstate->generation_stats = NULL;
 
     /* Prevent a subtle bug that affects sub-interpreters that use basic
      * single-phase init extensions (m_size == -1).  Those extensions cause 
objects

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to