gh-151126: Fix crash on unset memory error in ctypes.get_errno (#151382)

This commit is contained in:
sobolevn
2026-06-12 14:03:21 +03:00
committed by GitHub
parent c37599200f
commit 6b217ea90b
2 changed files with 5 additions and 2 deletions
@@ -0,0 +1,2 @@
Fix crash on unset :exc:`MemoryError` on allocation failure in
:func:`ctypes.get_errno`.
+3 -2
View File
@@ -168,8 +168,9 @@ _ctypes_get_errobj(ctypes_state *st, int **pspace)
}
else {
void *space = PyMem_Calloc(2, sizeof(int));
if (space == NULL)
return NULL;
if (space == NULL) {
return PyErr_NoMemory();
}
errobj = PyCapsule_New(space, CTYPES_CAPSULE_NAME_PYMEM, pymem_destructor);
if (errobj == NULL) {
PyMem_Free(space);