mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
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:
parent
3a521f0b61
commit
4c49da0cb7
17 changed files with 113 additions and 27 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue