]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-146527: Fix memory leak in _PyGC_Fini() (#150969)
authorVictor Stinner <vstinner@python.org>
Fri, 5 Jun 2026 13:43:05 +0000 (15:43 +0200)
committerGitHub <noreply@github.com>
Fri, 5 Jun 2026 13:43:05 +0000 (13:43 +0000)
Free generation_stats allocated by _PyGC_Init().

Fix Python/gc.c: Python/gc_free_threading.c was already fixed.

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