Skip to content

Commit cb64d43

Browse files
lpyu001miss-islington
authored andcommitted
gh-151126: Fix PyErr_NoMemory errors in _ctypes.c (GH-152720)
(cherry picked from commit d807210) Co-authored-by: stevens <lipengyu@kylinos.cn>
1 parent edbc1fe commit cb64d43

2 files changed

Lines changed: 4 additions & 0 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 caused by failing to set :exc:`MemoryError` on allocation failure
2+
when passing :class:`ctypes.Structure` or :class:`ctypes.Union` instances by
3+
value to ctypes foreign functions.

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ StructUnionType_paramfunc(ctypes_state *st, CDataObject *self)
673673
if ((size_t)self->b_size > sizeof(void*)) {
674674
ptr = PyMem_Malloc(self->b_size);
675675
if (ptr == NULL) {
676+
PyErr_NoMemory();
676677
return NULL;
677678
}
678679
memcpy(ptr, self->b_ptr, self->b_size);

0 commit comments

Comments
 (0)