[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 a580029f11)

Co-authored-by: Ivy Xu <fakeshadow1337@gmail.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2026-06-25 13:15:27 +02:00 committed by GitHub
parent 06506197c9
commit d6fd5378e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View file

@ -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.

View file

@ -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;