]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-151126: Fix missing memory errors in `_interpretersmodule.c` (#153765)
authorstevens <lipengyu@kylinos.cn>
Wed, 15 Jul 2026 12:40:54 +0000 (20:40 +0800)
committerGitHub <noreply@github.com>
Wed, 15 Jul 2026 12:40:54 +0000 (12:40 +0000)
gh-151126: Fix missing memory errors in `_interpretersmodule.c` (#151624)

(cherry picked from commit 05225aa06a4c5eceaa2eb29e99c2d44d2dbfe295)

Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-16-00-10.gh-issue-151126.tBqn6I.rst [new file with mode: 0644]
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 (file)
index 0000000..d495df4
--- /dev/null
@@ -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`.
index 4ff73d32d2095bde507b97b37fd2d4c7c97bf748..f5b43f1e47f948163a26560ff47e3de885d7bbcf 100644 (file)
@@ -92,7 +92,7 @@ xibufferview_from_xid(PyTypeObject *cls, _PyCrossInterpreterData *data)
     assert(_PyCrossInterpreterData_INTERPID(data) >= 0);
     XIBufferViewObject *self = PyObject_Malloc(sizeof(XIBufferViewObject));
     if (self == NULL) {
-        return NULL;
+        return PyErr_NoMemory();
     }
     PyObject_Init((PyObject *)self, cls);
     self->view = (Py_buffer *)_PyCrossInterpreterData_DATA(data);
@@ -174,6 +174,7 @@ _memoryview_shared(PyThreadState *tstate, PyObject *obj,
 {
     Py_buffer *view = PyMem_RawMalloc(sizeof(Py_buffer));
     if (view == NULL) {
+        PyErr_NoMemory();
         return -1;
     }
     if (PyObject_GetBuffer(obj, view, PyBUF_FULL_RO) < 0) {