Skip to content

Commit 7b16d6c

Browse files
[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 05225aa) Co-authored-by: stevens <lipengyu@kylinos.cn>
1 parent 00b8dab commit 7b16d6c

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a crash when sharing :class:`memoryview` objects between interpreters
2+
fails due to running out of memory. It now raises a proper
3+
:exc:`MemoryError`.

Modules/_interpretersmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ xibufferview_from_buffer(PyTypeObject *cls, Py_buffer *view, int64_t interpid)
137137

138138
Py_buffer *copied = PyMem_RawMalloc(sizeof(Py_buffer));
139139
if (copied == NULL) {
140-
return NULL;
140+
return PyErr_NoMemory();
141141
}
142142
/* This steals the view->obj reference */
143143
*copied = *view;
144144

145145
xibufferview *self = PyObject_Malloc(sizeof(xibufferview));
146146
if (self == NULL) {
147147
PyMem_RawFree(copied);
148-
return NULL;
148+
return PyErr_NoMemory();
149149
}
150150
PyObject_Init(&self->base, cls);
151151
*self = (xibufferview){
@@ -270,6 +270,7 @@ _pybuffer_shared(PyThreadState *tstate, PyObject *obj, _PyXIData_t *data)
270270
{
271271
struct xibuffer *view = PyMem_RawMalloc(sizeof(struct xibuffer));
272272
if (view == NULL) {
273+
PyErr_NoMemory();
273274
return -1;
274275
}
275276
view->used = 0;

0 commit comments

Comments
 (0)