Skip to content

Commit 6b217ea

Browse files
authored
gh-151126: Fix crash on unset memory error in ctypes.get_errno (#151382)
1 parent c375992 commit 6b217ea

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix crash on unset :exc:`MemoryError` on allocation failure in
2+
:func:`ctypes.get_errno`.

Modules/_ctypes/callproc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ _ctypes_get_errobj(ctypes_state *st, int **pspace)
168168
}
169169
else {
170170
void *space = PyMem_Calloc(2, sizeof(int));
171-
if (space == NULL)
172-
return NULL;
171+
if (space == NULL) {
172+
return PyErr_NoMemory();
173+
}
173174
errobj = PyCapsule_New(space, CTYPES_CAPSULE_NAME_PYMEM, pymem_destructor);
174175
if (errobj == NULL) {
175176
PyMem_Free(space);

0 commit comments

Comments
 (0)