mirror of
https://github.com/python/cpython.git
synced 2025-10-19 16:03:42 +00:00
[3.13] gh-109700: fix interpreter finalization while handling memory error (GH-136342) (#136353)
gh-109700: fix interpreter finalization while handling memory error (GH-136342)
(cherry picked from commit 0c3e3da195
)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
bc3390c00a
commit
2362cb6c6e
1 changed files with 7 additions and 7 deletions
|
@ -1717,8 +1717,10 @@ finalize_modules(PyThreadState *tstate)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Stop watching __builtin__ modifications
|
// 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);
|
PyObject *modules = _PyImport_GetModules(interp);
|
||||||
if (modules == NULL) {
|
if (modules == NULL) {
|
||||||
// Already done
|
// Already done
|
||||||
|
@ -2385,15 +2387,13 @@ new_interpreter(PyThreadState **tstate_p,
|
||||||
error:
|
error:
|
||||||
*tstate_p = NULL;
|
*tstate_p = NULL;
|
||||||
if (tstate != NULL) {
|
if (tstate != NULL) {
|
||||||
PyThreadState_Clear(tstate);
|
Py_EndInterpreter(tstate);
|
||||||
_PyThreadState_Detach(tstate);
|
} else {
|
||||||
PyThreadState_Delete(tstate);
|
PyInterpreterState_Delete(interp);
|
||||||
}
|
}
|
||||||
if (save_tstate != NULL) {
|
if (save_tstate != NULL) {
|
||||||
_PyThreadState_Attach(save_tstate);
|
_PyThreadState_Attach(save_tstate);
|
||||||
}
|
}
|
||||||
PyInterpreterState_Delete(interp);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue