Skip to content

Commit 0650619

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

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
@@ -144,15 +144,15 @@ xibufferview_from_buffer(PyTypeObject *cls, Py_buffer *view, int64_t interpid)
144144

145145
Py_buffer *copied = PyMem_RawMalloc(sizeof(Py_buffer));
146146
if (copied == NULL) {
147-
return NULL;
147+
return PyErr_NoMemory();
148148
}
149149
/* This steals the view->obj reference */
150150
*copied = *view;
151151

152152
xibufferview *self = PyObject_Malloc(sizeof(xibufferview));
153153
if (self == NULL) {
154154
PyMem_RawFree(copied);
155-
return NULL;
155+
return PyErr_NoMemory();
156156
}
157157
PyObject_Init(&self->base, cls);
158158
*self = (xibufferview){
@@ -277,6 +277,7 @@ _pybuffer_shared(PyThreadState *tstate, PyObject *obj, _PyXIData_t *data)
277277
{
278278
struct xibuffer *view = PyMem_RawMalloc(sizeof(struct xibuffer));
279279
if (view == NULL) {
280+
PyErr_NoMemory();
280281
return -1;
281282
}
282283
view->used = 0;

0 commit comments

Comments
 (0)