bpo-35436: Add missing PyErr_NoMemory() calls and other minor bug fixes. (GH-11015)
Set MemoryError when appropriate, add missing failure checks,
and fix some potential leaks.
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index 824690f..dd0997a 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -816,11 +816,13 @@
}
bufsize = newsize;
- buf = PyMem_Realloc(buf, (bufsize + 1) * sizeof(wchar_t));
- if (!buf) {
+ wchar_t *tmp = PyMem_Realloc(buf,
+ (bufsize + 1) * sizeof(wchar_t));
+ if (tmp == NULL) {
PyMem_Free(buf);
return NULL;
}
+ buf = tmp;
}
subbuf = read_console_w(self->handle, bufsize - len, &n);