diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-07-16-10-12-32.gh-issue-153797.VqQ8r1.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-16-10-12-32.gh-issue-153797.VqQ8r1.rst new file mode 100644 index 00000000000000..6394c5f37ffc4d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-16-10-12-32.gh-issue-153797.VqQ8r1.rst @@ -0,0 +1,2 @@ +Fix a crash that could occur after an out-of-memory error when re-importing +an extension module. diff --git a/Python/import.c b/Python/import.c index 63e23e21beb126..710099151d1f27 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2008,7 +2008,7 @@ reload_singlephase_extension(PyThreadState *tstate, Py_ssize_t index = _get_cached_module_index(cached); if (_modules_by_index_set(tstate->interp, index, mod) < 0) { - PyMapping_DelItem(modules, info->name); + remove_module(tstate, info->name); Py_DECREF(mod); return NULL; }