Skip to content

Commit 8feedcc

Browse files
miss-islingtonByteFlowing1337sobolevn
authored
[3.13] gh-151126: Add missing PyErr_NoMemory in _winapi.c (GH-151588) (#152184)
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 b435079 commit 8feedcc

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
@@ -1668,6 +1668,9 @@ _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path)
16681668
}
16691669
PyMem_Free((void *)buffer);
16701670
}
1671+
else {
1672+
PyErr_NoMemory();
1673+
}
16711674
} else {
16721675
PyErr_SetFromWindowsErr(0);
16731676
}
@@ -2371,6 +2374,7 @@ _winapi_BatchedWaitForMultipleObjects_impl(PyObject *module,
23712374
while (i < nhandles) {
23722375
BatchedWaitData *data = (BatchedWaitData*)PyMem_Malloc(sizeof(BatchedWaitData));
23732376
if (!data) {
2377+
PyErr_NoMemory();
23742378
goto error;
23752379
}
23762380
thread_data[thread_count++] = data;

0 commit comments

Comments
 (0)