Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization

* Replace malloc() with PyMem_RawMalloc()
* Replace PyMem_Malloc() with PyMem_RawMalloc() where the GIL is not held.
* _Py_char2wchar() now returns a buffer allocated by PyMem_RawMalloc(), instead
  of PyMem_Malloc()
This commit is contained in:
Victor Stinner 2013-07-07 16:25:15 +02:00
parent 51fa458d0a
commit 1a7425f67a
8 changed files with 76 additions and 76 deletions

View file

@ -343,7 +343,7 @@ search_for_prefix(wchar_t *argv0_path, wchar_t *home, wchar_t *_prefix)
if (vpath != NULL) {
wcscpy(prefix, argv0_path);
joinpath(prefix, vpath);
PyMem_Free(vpath);
PyMem_RawFree(vpath);
joinpath(prefix, L"Lib");
joinpath(prefix, LANDMARK);
if (ismodule(prefix))
@ -554,8 +554,7 @@ calculate_path(void)
}
else
progpath[0] = '\0';
if (path_buffer != NULL)
PyMem_Free(path_buffer);
PyMem_RawFree(path_buffer);
if (progpath[0] != SEP && progpath[0] != '\0')
absolutize(progpath);
wcsncpy(argv0_path, progpath, MAXPATHLEN);
@ -597,7 +596,7 @@ calculate_path(void)
/* Use the location of the library as the progpath */
wcsncpy(argv0_path, wbuf, MAXPATHLEN);
}
PyMem_Free(wbuf);
PyMem_RawFree(wbuf);
}
#endif
@ -808,11 +807,10 @@ calculate_path(void)
else
wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN);
PyMem_Free(_pythonpath);
PyMem_Free(_prefix);
PyMem_Free(_exec_prefix);
if (rtpypath != NULL)
PyMem_Free(rtpypath);
PyMem_RawFree(_pythonpath);
PyMem_RawFree(_prefix);
PyMem_RawFree(_exec_prefix);
PyMem_RawFree(rtpypath);
}
@ -822,7 +820,7 @@ Py_SetPath(const wchar_t *path)
{
if (module_search_path != NULL) {
if (module_search_path_malloced)
PyMem_Free(module_search_path);
PyMem_RawFree(module_search_path);
module_search_path = NULL;
module_search_path_malloced = 0;
}
@ -831,7 +829,7 @@ Py_SetPath(const wchar_t *path)
wchar_t *prog = Py_GetProgramName();
wcsncpy(progpath, prog, MAXPATHLEN);
exec_prefix[0] = prefix[0] = L'\0';
module_search_path = PyMem_Malloc((wcslen(path) + 1) * sizeof(wchar_t));
module_search_path = PyMem_RawMalloc((wcslen(path) + 1) * sizeof(wchar_t));
module_search_path_malloced = 1;
if (module_search_path != NULL)
wcscpy(module_search_path, path);