Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-109700: fix interpreter finalization while handling memory error (G…
…H-136342)

(cherry picked from commit 0c3e3da)

Co-authored-by: Kumar Aditya <[email protected]>
  • Loading branch information
kumaraditya303 authored and miss-islington committed Jul 7, 2025
commit 981fce1ad09333bdf5f648d9cde964e8c80aa602
14 changes: 7 additions & 7 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1717,8 +1717,10 @@ finalize_modules(PyThreadState *tstate)
#endif

// Stop watching __builtin__ modifications
PyDict_Unwatch(0, interp->builtins);

if (PyDict_Unwatch(0, interp->builtins) < 0) {
// might happen if interp is cleared before watching the __builtin__
PyErr_Clear();
}
PyObject *modules = _PyImport_GetModules(interp);
if (modules == NULL) {
// Already done
Expand Down Expand Up @@ -2385,15 +2387,13 @@ new_interpreter(PyThreadState **tstate_p,
error:
*tstate_p = NULL;
if (tstate != NULL) {
PyThreadState_Clear(tstate);
_PyThreadState_Detach(tstate);
PyThreadState_Delete(tstate);
Py_EndInterpreter(tstate);
} else {
PyInterpreterState_Delete(interp);
}
if (save_tstate != NULL) {
_PyThreadState_Attach(save_tstate);
}
PyInterpreterState_Delete(interp);

return status;
}

Expand Down
Loading