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.
This commit is contained in:
Zackery Spytz 2018-12-07 03:11:30 -07:00 committed by Serhiy Storchaka
parent 3a521f0b61
commit 4c49da0cb7
17 changed files with 113 additions and 27 deletions

View file

@ -575,6 +575,9 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path)
size_t prefixlen = wcslen(prefix);
wchar_t *buf = (wchar_t*)PyMem_RawMalloc(bufsiz * sizeof(wchar_t));
if (buf == NULL) {
goto error;
}
buf[0] = '\0';
while (!feof(sp_file)) {
@ -603,17 +606,22 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path)
DWORD wn = MultiByteToWideChar(CP_UTF8, 0, line, -1, NULL, 0);
wchar_t *wline = (wchar_t*)PyMem_RawMalloc((wn + 1) * sizeof(wchar_t));
if (wline == NULL) {
goto error;
}
wn = MultiByteToWideChar(CP_UTF8, 0, line, -1, wline, wn + 1);
wline[wn] = '\0';
size_t usedsiz = wcslen(buf);
while (usedsiz + wn + prefixlen + 4 > bufsiz) {
bufsiz += MAXPATHLEN;
buf = (wchar_t*)PyMem_RawRealloc(buf, (bufsiz + 1) * sizeof(wchar_t));
if (!buf) {
wchar_t *tmp = (wchar_t*)PyMem_RawRealloc(buf, (bufsiz + 1) *
sizeof(wchar_t));
if (tmp == NULL) {
PyMem_RawFree(wline);
goto error;
}
buf = tmp;
}
if (usedsiz) {