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 000000000000000..f37e2585a9a3b27 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-16-31-00.gh-issue-151126.phAWIG.rst @@ -0,0 +1,2 @@ +Raise :exc:`MemoryError` on allocation failure in +``_PyXIData_InitWithSize``. diff --git a/Python/crossinterp.c b/Python/crossinterp.c index ed77c1be646e275..abd94e74f972b8e 100644 --- a/Python/crossinterp.c +++ b/Python/crossinterp.c @@ -388,6 +388,7 @@ _PyXIData_InitWithSize(_PyXIData_t *xidata, _PyXIData_Init(xidata, interp, NULL, obj, new_object); xidata->data = PyMem_RawCalloc(1, size); if (xidata->data == NULL) { + PyErr_NoMemory(); return -1; } xidata->free = PyMem_RawFree;