Skip to content

Commit 0df6b24

Browse files
miss-islingtonlpyu001sobolevn
authored
[3.14] gh-151126: Fix PyErr_NoMemory errors in _ctypes.c (GH-152720) (#153709)
gh-151126: Fix `PyErr_NoMemory` errors in `_ctypes.c` (GH-152720) (cherry picked from commit d807210) Co-authored-by: stevens <lipengyu@kylinos.cn> Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent a5e78cb commit 0df6b24

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
@@ -669,6 +669,7 @@ StructUnionType_paramfunc(ctypes_state *st, CDataObject *self)
669669
if ((size_t)self->b_size > sizeof(void*)) {
670670
ptr = PyMem_Malloc(self->b_size);
671671
if (ptr == NULL) {
672+
PyErr_NoMemory();
672673
return NULL;
673674
}
674675
memcpy(ptr, self->b_ptr, self->b_size);

0 commit comments

Comments
 (0)