Skip to content

Commit 2315d94

Browse files
authored
gh-159739: Clear free-threaded GC worklists after early errors (#159979)
Backport to 3.15 and 3.14.
1 parent 4101d59 commit 2315d94

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
@@ -2123,6 +2123,7 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state,
21232123
int err = gc_mark_alive_from_roots(interp, state);
21242124
if (err < 0) {
21252125
_PyEval_StartTheWorld(interp);
2126+
cleanup_worklist(&state->objs_to_decref);
21262127
PyErr_NoMemory();
21272128
return;
21282129
}
@@ -2133,6 +2134,9 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state,
21332134
int err = deduce_unreachable_heap(interp, state);
21342135
if (err < 0) {
21352136
_PyEval_StartTheWorld(interp);
2137+
cleanup_worklist(&state->unreachable);
2138+
cleanup_worklist(&state->legacy_finalizers);
2139+
cleanup_worklist(&state->objs_to_decref);
21362140
PyErr_NoMemory();
21372141
return;
21382142
}

0 commit comments

Comments
 (0)