From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 25 Jun 2026 10:35:45 +0000 (+0200) Subject: [3.15] gh-151126: Fix missing memory errors in `_interpretersmodule.c` (GH-151624... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06506197c9633f29bcd1451588481c3283841d60;p=thirdparty%2FPython%2Fcpython.git [3.15] gh-151126: Fix missing memory errors in `_interpretersmodule.c` (GH-151624) (#152169) gh-151126: Fix missing memory errors in `_interpretersmodule.c` (GH-151624) (cherry picked from commit 05225aa06a4c5eceaa2eb29e99c2d44d2dbfe295) Co-authored-by: stevens --- diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-16-00-10.gh-issue-151126.tBqn6I.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-16-00-10.gh-issue-151126.tBqn6I.rst new file mode 100644 index 000000000000..d495df43ede9 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-16-00-10.gh-issue-151126.tBqn6I.rst @@ -0,0 +1,3 @@ +Fix a crash when sharing :class:`memoryview` objects between interpreters +fails due to running out of memory. It now raises a proper +:exc:`MemoryError`. diff --git a/Modules/_interpretersmodule.c b/Modules/_interpretersmodule.c index d024dee906de..15bfd35a8080 100644 --- a/Modules/_interpretersmodule.c +++ b/Modules/_interpretersmodule.c @@ -144,7 +144,7 @@ xibufferview_from_buffer(PyTypeObject *cls, Py_buffer *view, int64_t interpid) Py_buffer *copied = PyMem_RawMalloc(sizeof(Py_buffer)); if (copied == NULL) { - return NULL; + return PyErr_NoMemory(); } /* This steals the view->obj reference */ *copied = *view; @@ -152,7 +152,7 @@ xibufferview_from_buffer(PyTypeObject *cls, Py_buffer *view, int64_t interpid) xibufferview *self = PyObject_Malloc(sizeof(xibufferview)); if (self == NULL) { PyMem_RawFree(copied); - return NULL; + return PyErr_NoMemory(); } PyObject_Init(&self->base, cls); *self = (xibufferview){ @@ -277,6 +277,7 @@ _pybuffer_shared(PyThreadState *tstate, PyObject *obj, _PyXIData_t *data) { struct xibuffer *view = PyMem_RawMalloc(sizeof(struct xibuffer)); if (view == NULL) { + PyErr_NoMemory(); return -1; } view->used = 0;