]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-151126: Add missing `PyErr_NoMemory` in `_winapi.c` (GH-151588) (#152183)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 25 Jun 2026 11:14:19 +0000 (13:14 +0200)
committerGitHub <noreply@github.com>
Thu, 25 Jun 2026 11:14:19 +0000 (11:14 +0000)
gh-151126: Add missing `PyErr_NoMemory` in `_winapi.c` (GH-151588)
(cherry picked from commit a580029f1168cf87707b157865b6a6b89a77b7ad)

Co-authored-by: Ivy Xu <fakeshadow1337@gmail.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-46-07.gh-issue-151126.vhTL0T.rst [new file with mode: 0644]
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 (file)
index 0000000..6f2d230
--- /dev/null
@@ -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.
index 557029f66ae7072a0d8ded36546cb5a2bcd60c89..f4e73828121c80c7f45d8e8bdd4d81246f2fc7b9 100644 (file)
@@ -1671,6 +1671,9 @@ _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path)
             }
             PyMem_Free((void *)buffer);
         }
+        else {
+            PyErr_NoMemory();
+        }
     } else {
         PyErr_SetFromWindowsErr(0);
     }
@@ -2374,6 +2377,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;