File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -294,8 +294,6 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
294294 Py_CLEAR (interp -> codec_error_registry );
295295 Py_CLEAR (interp -> modules );
296296 Py_CLEAR (interp -> modules_by_index );
297- Py_CLEAR (interp -> sysdict );
298- Py_CLEAR (interp -> builtins );
299297 Py_CLEAR (interp -> builtins_copy );
300298 Py_CLEAR (interp -> importlib );
301299 Py_CLEAR (interp -> import_func );
@@ -308,6 +306,14 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
308306 if (_PyRuntimeState_GetFinalizing (runtime ) == NULL ) {
309307 _PyWarnings_Fini (interp );
310308 }
309+ /* We don't clear sysdict and builtins until the end of this function.
310+ Because clearing other attributes can execute arbitrary Python code
311+ which requires sysdict and builtins. */
312+ PyDict_Clear (interp -> sysdict );
313+ PyDict_Clear (interp -> builtins );
314+ Py_CLEAR (interp -> sysdict );
315+ Py_CLEAR (interp -> builtins );
316+
311317 // XXX Once we have one allocator per interpreter (i.e.
312318 // per-interpreter GC) we must ensure that all of the interpreter's
313319 // objects have been cleaned up at the point.
You can’t perform that action at this time.
0 commit comments