gh-151126: Fix missing memory errors in `_interpretersmodule.c` (#151… · python/cpython@05225aa

GitHub

GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources

File tree

Misc/NEWS.d/next/Core_and_Builtins

Modules

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`.

Original file line numberDiff line numberDiff line change@@ -144,15 +144,15 @@ xibufferview_from_buffer(PyTypeObject *cls, Py_buffer *view, int64_t interpid)

144144145145Py_buffer*copied=PyMem_RawMalloc(sizeof(Py_buffer));

146146if (copied==NULL) {

147-returnNULL;

147+returnPyErr_NoMemory();

148148 }

149149/* This steals the view->obj reference */

150150*copied=*view;

151151152152xibufferview*self=PyObject_Malloc(sizeof(xibufferview));

153153if (self==NULL) {

154154PyMem_RawFree(copied);

155-returnNULL;

155+returnPyErr_NoMemory();

156156 }

157157PyObject_Init(&self->base, cls);

158158*self= (xibufferview){

@@ -277,6 +277,7 @@ _pybuffer_shared(PyThreadState *tstate, PyObject *obj, _PyXIData_t *data)

277277{

278278structxibuffer*view=PyMem_RawMalloc(sizeof(structxibuffer));

279279if (view==NULL) {

280+PyErr_NoMemory();

280281return-1;

281282 }

282283view->used=0;