Skip to content

Commit a580029

Browse files
gh-151126: Add missing PyErr_NoMemory in _winapi.c (#151588)
Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent a009328 commit a580029

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
@@ -1684,6 +1684,9 @@ _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path)
16841684
}
16851685
PyMem_Free((void *)buffer);
16861686
}
1687+
else {
1688+
PyErr_NoMemory();
1689+
}
16871690
} else {
16881691
PyErr_SetFromWindowsErr(0);
16891692
}
@@ -2394,6 +2397,7 @@ _winapi_BatchedWaitForMultipleObjects_impl(PyObject *module,
23942397
while (i < nhandles) {
23952398
BatchedWaitData *data = (BatchedWaitData*)PyMem_Malloc(sizeof(BatchedWaitData));
23962399
if (!data) {
2400+
PyErr_NoMemory();
23972401
goto error;
23982402
}
23992403
thread_data[thread_count++] = data;

0 commit comments

Comments
 (0)