]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-146527: Fix memory leak in _PyGC_Fini() (GH-150969) (#150970)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 5 Jun 2026 14:11:37 +0000 (16:11 +0200)
committerGitHub <noreply@github.com>
Fri, 5 Jun 2026 14:11:37 +0000 (14:11 +0000)
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 <vstinner@python.org>
Python/gc.c

index 54ac1b089e503d051374d87e9b597d70aa699be6..201c621bcc3cb9b5840387a385bd647dfca6b88c 100644 (file)
@@ -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