https://github.com/python/cpython/commit/7c3f0bd9b0e51edf8b9b8e4eb4eafb45e41c405b commit: 7c3f0bd9b0e51edf8b9b8e4eb4eafb45e41c405b branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: sobolevn <[email protected]> date: 2026-06-12T11:27:19Z summary:
[3.13] gh-151126: Fix crash on unset memory error in `ctypes.get_errno` (GH-151382) (#151400) gh-151126: Fix crash on unset memory error in `ctypes.get_errno` (GH-151382) (cherry picked from commit 6b217ea90b9cd694fded6308bc796e324bbacd19) Co-authored-by: sobolevn <[email protected]> files: A Misc/NEWS.d/next/Library/2026-06-12-00-04-34.gh-issue-151126.aHaBYq.rst M Modules/_ctypes/callproc.c diff --git a/Misc/NEWS.d/next/Library/2026-06-12-00-04-34.gh-issue-151126.aHaBYq.rst b/Misc/NEWS.d/next/Library/2026-06-12-00-04-34.gh-issue-151126.aHaBYq.rst new file mode 100644 index 000000000000000..20ef69d5de5ac55 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-12-00-04-34.gh-issue-151126.aHaBYq.rst @@ -0,0 +1,2 @@ +Fix crash on unset :exc:`MemoryError` on allocation failure in +:func:`ctypes.get_errno`. diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 8f94d19024e62cb..066cbb99bdd758f 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -181,8 +181,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); _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
