]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151126: Fix crash on unset memory error in `ctypes.get_errno` (#151382)
authorsobolevn <mail@sobolevn.me>
Fri, 12 Jun 2026 11:03:21 +0000 (14:03 +0300)
committerGitHub <noreply@github.com>
Fri, 12 Jun 2026 11:03:21 +0000 (14:03 +0300)
Misc/NEWS.d/next/Library/2026-06-12-00-04-34.gh-issue-151126.aHaBYq.rst [new file with mode: 0644]
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 (file)
index 0000000..20ef69d
--- /dev/null
@@ -0,0 +1,2 @@
+Fix crash on unset :exc:`MemoryError` on allocation failure in
+:func:`ctypes.get_errno`.
index e453cfeec9cc8ca01aa94a6d36f30149b014fa32..ccc57e347b07acf41be2ba683de48360ad69d517 100644 (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);