Skip to content

Commit b93dabc

Browse files
[3.14] gh-159739: Clear free-threaded GC worklists after early errors (GH-159979) (#160017)
(cherry picked from commit 2315d94) Co-authored-by: Jelle Zijlstra <jelle@openai.com>
1 parent 06a11df commit b93dabc

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix reference leaks when free-threaded garbage collection aborts early because
2+
of an allocation error.

‎Python/gc_free_threading.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,7 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state,
22292229
int err = gc_mark_alive_from_roots(interp, state);
22302230
if (err < 0) {
22312231
_PyEval_StartTheWorld(interp);
2232+
cleanup_worklist(&state->objs_to_decref);
22322233
PyErr_NoMemory();
22332234
return;
22342235
}
@@ -2239,6 +2240,9 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state,
22392240
int err = deduce_unreachable_heap(interp, state);
22402241
if (err < 0) {
22412242
_PyEval_StartTheWorld(interp);
2243+
cleanup_worklist(&state->unreachable);
2244+
cleanup_worklist(&state->legacy_finalizers);
2245+
cleanup_worklist(&state->objs_to_decref);
22422246
PyErr_NoMemory();
22432247
return;
22442248
}

0 commit comments

Comments
 (0)