https://github.com/python/cpython/commit/2315d94664f0a1c93ef43272b9c200ad4b04c709
commit: 2315d94664f0a1c93ef43272b9c200ad4b04c709
branch: main
author: Jelle Zijlstra <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-10-20T21:32:19-07:00
summary:
gh-159739: Clear free-threaded GC worklists after early errors (#159979)
Backport to 3.15 and 3.14.
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-10-20-00-00-00.gh-issue-159739.da0f04.rst
M Python/gc_free_threading.c
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-20-00-00-00.gh-issue-159739.da0f04.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-20-00-00-00.gh-issue-159739.da0f04.rst
new file mode 100644
index 00000000000000..386eb5535b7025
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-20-00-00-00.gh-issue-159739.da0f04.rst
@@ -0,0 +1,2 @@
+Fix reference leaks when free-threaded garbage collection aborts early because
+of an allocation error.
diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c
index 264afeebd54f89..e8ed866312c94b 100644
--- a/Python/gc_free_threading.c
+++ b/Python/gc_free_threading.c
@@ -2123,6 +2123,7 @@ gc_collect_internal(PyInterpreterState *interp, struct
collection_state *state,
int err = gc_mark_alive_from_roots(interp, state);
if (err < 0) {
_PyEval_StartTheWorld(interp);
+ cleanup_worklist(&state->objs_to_decref);
PyErr_NoMemory();
return;
}
@@ -2133,6 +2134,9 @@ gc_collect_internal(PyInterpreterState *interp, struct
collection_state *state,
int err = deduce_unreachable_heap(interp, state);
if (err < 0) {
_PyEval_StartTheWorld(interp);
+ cleanup_worklist(&state->unreachable);
+ cleanup_worklist(&state->legacy_finalizers);
+ cleanup_worklist(&state->objs_to_decref);
PyErr_NoMemory();
return;
}
_______________________________________________
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]