diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-16-31-00.gh-issue-151126.phAWIG.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-16-31-00.gh-issue-151126.phAWIG.rst new file mode 100644 index 00000000000000..b1459de1c1596d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-16-31-00.gh-issue-151126.phAWIG.rst @@ -0,0 +1 @@ +Fix a crash when allocation failure occurs during :ref:`interp-object-sharing`. diff --git a/Python/crossinterp.c b/Python/crossinterp.c index b8dd5f11c2a44c..d189d7bcefe313 100644 --- a/Python/crossinterp.c +++ b/Python/crossinterp.c @@ -388,6 +388,8 @@ _PyXIData_InitWithSize(_PyXIData_t *xidata, _PyXIData_Init(xidata, interp, NULL, obj, new_object); xidata->data = PyMem_RawCalloc(1, size); if (xidata->data == NULL) { + Py_CLEAR(xidata->obj); + PyErr_NoMemory(); return -1; } xidata->free = PyMem_RawFree;