diff options
author | Zackery Spytz <zspytz@gmail.com> | 2018-12-07 10:11:30 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2018-12-07 10:11:30 (GMT) |
commit | 4c49da0cb7434c676d70b9ccf38aca82ac0d64a9 (patch) | |
tree | aae3660f9a5bc462830107cf2311b2557898e268 /PC | |
parent | 3a521f0b6167628f975c773b56c7daf8d33d6f40 (diff) | |
download | cpython-4c49da0cb7434c676d70b9ccf38aca82ac0d64a9.zip cpython-4c49da0cb7434c676d70b9ccf38aca82ac0d64a9.tar.gz cpython-4c49da0cb7434c676d70b9ccf38aca82ac0d64a9.tar.bz2 |
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.
Diffstat (limited to 'PC')
-rw-r--r-- | PC/getpathp.c | 12 | ||||
-rw-r--r-- | PC/launcher.c | 3 |
2 files changed, 13 insertions, 2 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c index 452501a..76d3a08 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -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) { diff --git a/PC/launcher.c b/PC/launcher.c index 0242f26..4c620da 100644 --- a/PC/launcher.c +++ b/PC/launcher.c @@ -1763,6 +1763,9 @@ process(int argc, wchar_t ** argv) } cch += (DWORD)wcslen(PYTHON_EXECUTABLE) + 1 + 1; /* include sep and null */ executable = (wchar_t *)malloc(cch * sizeof(wchar_t)); + if (executable == NULL) { + error(RC_NO_MEMORY, L"A memory allocation failed"); + } cch_actual = MultiByteToWideChar(CP_UTF8, 0, start, len, executable, cch); if (!cch_actual) { error(RC_BAD_VENV_CFG, L"Cannot decode home path in '%ls'", |