Skip to content

Commit d6fd537

Browse files
miss-islingtonByteFlowing1337sobolevn
authored
[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 a580029) Co-authored-by: Ivy Xu <fakeshadow1337@gmail.com> Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent 0650619 commit d6fd537

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
@@ -1677,6 +1677,9 @@ _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path)
16771677
}
16781678
PyMem_Free((void *)buffer);
16791679
}
1680+
else {
1681+
PyErr_NoMemory();
1682+
}
16801683
} else {
16811684
PyErr_SetFromWindowsErr(0);
16821685
}
@@ -2387,6 +2390,7 @@ _winapi_BatchedWaitForMultipleObjects_impl(PyObject *module,
23872390
while (i < nhandles) {
23882391
BatchedWaitData *data = (BatchedWaitData*)PyMem_Malloc(sizeof(BatchedWaitData));
23892392
if (!data) {
2393+
PyErr_NoMemory();
23902394
goto error;
23912395
}
23922396
thread_data[thread_count++] = data;

0 commit comments

Comments
 (0)