From b2ec8567887e5304cf2997fae4a23f09c9b80748 Mon Sep 17 00:00:00 2001 From: AN Long Date: Wed, 20 May 2026 05:31:00 +0900 Subject: [PATCH] gh-149983: Fix PyErr_NoMemory call without GIL in winconsoleio.c (GH-149984) (cherry picked from commit 3d2aa899bad1c0e274640dc0c4323f1744e73435) Co-authored-by: AN Long --- Modules/_io/winconsoleio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index 950b7fe241ccde..d7e81738828e0c 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -673,12 +673,13 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) { maxlen += 1; Py_BLOCK_THREADS newbuf = (wchar_t*)PyMem_Realloc(buf, maxlen * sizeof(wchar_t)); - Py_UNBLOCK_THREADS if (!newbuf) { sig = -1; PyErr_NoMemory(); + Py_UNBLOCK_THREADS break; } + Py_UNBLOCK_THREADS buf = newbuf; /* Only advance by n and not BUFSIZ in this case */ off += n;