Skip to content

Commit b51f606

Browse files
miss-islingtonByteFlowing1337sobolevn
authored
[3.14] gh-151126: Add missing PyErr_NoMemory in _winapi.c (GH-151588) (#152183)
gh-151126: Add missing `PyErr_NoMemory` in `_winapi.c` (GH-151588) (cherry picked from commit a580029) Co-authored-by: Ivy Xu <fakeshadow1337@gmail.com> Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent ab694a8 commit b51f606

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Avoid possible crash in ``_winapi.c`` where a device has no memory left. Now
2+
it properly raises a :exc:`MemoryError`. Patch by Ivy Xu.

Modules/_winapi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,9 @@ _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path)
16711671
}
16721672
PyMem_Free((void *)buffer);
16731673
}
1674+
else {
1675+
PyErr_NoMemory();
1676+
}
16741677
} else {
16751678
PyErr_SetFromWindowsErr(0);
16761679
}
@@ -2374,6 +2377,7 @@ _winapi_BatchedWaitForMultipleObjects_impl(PyObject *module,
23742377
while (i < nhandles) {
23752378
BatchedWaitData *data = (BatchedWaitData*)PyMem_Malloc(sizeof(BatchedWaitData));
23762379
if (!data) {
2380+
PyErr_NoMemory();
23772381
goto error;
23782382
}
23792383
thread_data[thread_count++] = data;

0 commit comments

Comments
 (0)