Skip to content

Commit 883cbee

Browse files
committed
bpo-38962: Fix reference leak in the per-subinterpreter gc
1 parent b96c6b0 commit 883cbee

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Python/pylifecycle.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,17 +1253,20 @@ finalize_interp_clear(PyThreadState *tstate)
12531253
{
12541254
int is_main_interp = _Py_IsMainInterpreter(tstate);
12551255

1256-
/* bpo-36854: Explicitly clear the codec registry
1257-
and trigger a GC collection */
1256+
/* bpo-36854: Explicitly clear the codec registry */
12581257
PyInterpreterState *interp = tstate->interp;
12591258
Py_CLEAR(interp->codec_search_path);
12601259
Py_CLEAR(interp->codec_search_cache);
12611260
Py_CLEAR(interp->codec_error_registry);
1262-
_PyGC_CollectNoFail();
12631261

12641262
/* Clear interpreter state and all thread states */
12651263
PyInterpreterState_Clear(tstate->interp);
12661264

1265+
/* Trigger a GC collection on subinterpreters*/
1266+
if (!is_main_interp) {
1267+
_PyGC_CollectNoFail();
1268+
}
1269+
12671270
finalize_interp_types(tstate, is_main_interp);
12681271

12691272
if (is_main_interp) {

0 commit comments

Comments
 (0)