https://github.com/python/cpython/commit/7b16d6cf8719c03008fc3a981f18dc1a2d7c1792
commit: 7b16d6cf8719c03008fc3a981f18dc1a2d7c1792
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-06-25T09:26:40Z
summary:

[3.14] gh-151126: Fix missing memory errors in `_interpretersmodule.c` 
(GH-151624) (#152170)

gh-151126: Fix missing memory errors in `_interpretersmodule.c` (GH-151624)
(cherry picked from commit 05225aa06a4c5eceaa2eb29e99c2d44d2dbfe295)

Co-authored-by: stevens <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-16-00-10.gh-issue-151126.tBqn6I.rst
M Modules/_interpretersmodule.c

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 00000000000000..d495df43ede932
--- /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 70adb59d6fdd54..f6abf1061325b6 100644
--- a/Modules/_interpretersmodule.c
+++ b/Modules/_interpretersmodule.c
@@ -137,7 +137,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;
@@ -145,7 +145,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){
@@ -270,6 +270,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;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to