https://github.com/python/cpython/commit/d6fd5378e33fd1e360c0dbcfe54dcbc65f06b4c1
commit: d6fd5378e33fd1e360c0dbcfe54dcbc65f06b4c1
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-06-25T11:15:27Z
summary:

[3.15] gh-151126: Add missing `PyErr_NoMemory` in `_winapi.c` (GH-151588) 
(#152182)

gh-151126: Add missing `PyErr_NoMemory` in `_winapi.c` (GH-151588)
(cherry picked from commit a580029f1168cf87707b157865b6a6b89a77b7ad)

Co-authored-by: Ivy Xu <[email protected]>
Co-authored-by: sobolevn <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-46-07.gh-issue-151126.vhTL0T.rst
M Modules/_winapi.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-46-07.gh-issue-151126.vhTL0T.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-46-07.gh-issue-151126.vhTL0T.rst
new file mode 100644
index 00000000000000..6f2d230b1dcfc0
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-46-07.gh-issue-151126.vhTL0T.rst
@@ -0,0 +1,2 @@
+Avoid possible crash in ``_winapi.c`` where a device has no memory left. Now
+it properly raises a :exc:`MemoryError`. Patch by Ivy Xu.
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index 74644a57eb9d47..683c19e4d0c4a1 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -1677,6 +1677,9 @@ _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR 
path)
             }
             PyMem_Free((void *)buffer);
         }
+        else {
+            PyErr_NoMemory();
+        }
     } else {
         PyErr_SetFromWindowsErr(0);
     }
@@ -2387,6 +2390,7 @@ _winapi_BatchedWaitForMultipleObjects_impl(PyObject 
*module,
     while (i < nhandles) {
         BatchedWaitData *data = 
(BatchedWaitData*)PyMem_Malloc(sizeof(BatchedWaitData));
         if (!data) {
+            PyErr_NoMemory();
             goto error;
         }
         thread_data[thread_count++] = data;

_______________________________________________
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]

Reply via email to