diff options
author | Sam Gross <colesbury@gmail.com> | 2024-08-08 12:48:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-08 12:48:17 -0400 |
commit | 2d9d3a9f5319ce3f850341d116b63cc51869df3a (patch) | |
tree | 6d5250d1af82d114d310655fe164c932b955ea4b /Python/pylifecycle.c | |
parent | 833eb106f5ebbac258f236d50177712d98a36715 (diff) | |
download | cpython-2d9d3a9f5319ce3f850341d116b63cc51869df3a.tar.gz cpython-2d9d3a9f5319ce3f850341d116b63cc51869df3a.zip |
gh-122697: Fix free-threading memory leaks at shutdown (#122703)
We were not properly accounting for interpreter memory leaks at
shutdown and had two sources of leaks:
* Objects that use deferred reference counting and were reachable via
static types outlive the final GC. We now disable deferred reference
counting on all objects if we are calling the GC due to interpreter
shutdown.
* `_PyMem_FreeDelayed` did not properly check for interpreter shutdown
so we had some memory blocks that were enqueued to be freed, but
never actually freed.
* `_PyType_FinalizeIdPool` wasn't called at interpreter shutdown.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 6b641c0775f..3a41c640fd9 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -28,6 +28,7 @@ #include "pycore_sliceobject.h" // _PySlice_Fini() #include "pycore_sysmodule.h" // _PySys_ClearAuditHooks() #include "pycore_traceback.h" // _Py_DumpTracebackThreads() +#include "pycore_typeid.h" // _PyType_FinalizeIdPool() #include "pycore_typeobject.h" // _PyTypes_InitTypes() #include "pycore_typevarobject.h" // _Py_clear_generic_types() #include "pycore_unicodeobject.h" // _PyUnicode_InitTypes() @@ -1832,6 +1833,9 @@ finalize_interp_types(PyInterpreterState *interp) _PyTypes_FiniTypes(interp); _PyTypes_Fini(interp); +#ifdef Py_GIL_DISABLED + _PyType_FinalizeIdPool(interp); +#endif _PyCode_Fini(interp); |