From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 25 Jun 2026 11:11:16 +0000 (+0200) Subject: [3.13] gh-151126: Add missing `PyErr_NoMemory` in `_winapi.c` (GH-151588) (#152184) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8feedccc114a5615e66af121d0b631fa64f28487;p=thirdparty%2FPython%2Fcpython.git [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 a580029f1168cf87707b157865b6a6b89a77b7ad) Co-authored-by: Ivy Xu Co-authored-by: sobolevn --- diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-46-07.gh-issue-151126.vhTL0T.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-46-07.gh-issue-151126.vhTL0T.rst new file mode 100644 index 000000000000..6f2d230b1dcf --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-46-07.gh-issue-151126.vhTL0T.rst @@ -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. diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 4d486400a092..19d55d113844 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -1668,6 +1668,9 @@ _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path) } PyMem_Free((void *)buffer); } + else { + PyErr_NoMemory(); + } } else { PyErr_SetFromWindowsErr(0); } @@ -2371,6 +2374,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;