summaryrefslogtreecommitdiff
path: root/PC/getpathp.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-07 16:25:15 +0200
committerVictor Stinner <victor.stinner@gmail.com>2013-07-07 16:25:15 +0200
commit0e6215070ac12c5aecdce573f75624eaa7ed056e (patch)
treea47bf1be6d6f37cd803cb515c5c68ca30dc9356d /PC/getpathp.c
parent37c223a89b1cd652ae397b07915c2dad168d3a0a (diff)
downloadcpython-0e6215070ac12c5aecdce573f75624eaa7ed056e.tar.gz
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()
Diffstat (limited to 'PC/getpathp.c')
-rw-r--r--PC/getpathp.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c
index 308eb87ed6..deb40e76f3 100644
--- a/PC/getpathp.c
+++ b/PC/getpathp.c
@@ -245,9 +245,9 @@ getpythonregpath(HKEY keyBase, int skipcore)
/* Tried to use sysget("winver") but here is too early :-( */
versionLen = strlen(PyWin_DLLVersionString);
/* Space for all the chars, plus one \0 */
- keyBuf = keyBufPtr = malloc(sizeof(keyPrefix) +
- sizeof(WCHAR)*(versionLen-1) +
- sizeof(keySuffix));
+ keyBuf = keyBufPtr = PyMem_RawMalloc(sizeof(keyPrefix) +
+ sizeof(WCHAR)*(versionLen-1) +
+ sizeof(keySuffix));
if (keyBuf==NULL) goto done;
memcpy(keyBufPtr, keyPrefix, sizeof(keyPrefix)-sizeof(WCHAR));
@@ -271,7 +271,7 @@ getpythonregpath(HKEY keyBase, int skipcore)
/* Allocate a temp array of char buffers, so we only need to loop
reading the registry once
*/
- ppPaths = malloc( sizeof(WCHAR *) * numKeys );
+ ppPaths = PyMem_RawMalloc( sizeof(WCHAR *) * numKeys );
if (ppPaths==NULL) goto done;
memset(ppPaths, 0, sizeof(WCHAR *) * numKeys);
/* Loop over all subkeys, allocating a temp sub-buffer. */
@@ -293,7 +293,7 @@ getpythonregpath(HKEY keyBase, int skipcore)
/* Find the value of the buffer size, malloc, then read it */
RegQueryValueExW(subKey, NULL, 0, NULL, NULL, &reqdSize);
if (reqdSize) {
- ppPaths[index] = malloc(reqdSize);
+ ppPaths[index] = PyMem_RawMalloc(reqdSize);
if (ppPaths[index]) {
RegQueryValueExW(subKey, NULL, 0, NULL,
(LPBYTE)ppPaths[index],
@@ -308,7 +308,7 @@ getpythonregpath(HKEY keyBase, int skipcore)
if (dataSize == 0) goto done;
/* original datasize from RegQueryInfo doesn't include the \0 */
- dataBuf = malloc((dataSize+1) * sizeof(WCHAR));
+ dataBuf = PyMem_RawMalloc((dataSize+1) * sizeof(WCHAR));
if (dataBuf) {
WCHAR *szCur = dataBuf;
DWORD reqdSize = dataSize;
@@ -346,14 +346,13 @@ getpythonregpath(HKEY keyBase, int skipcore)
done:
/* Loop freeing my temp buffers */
if (ppPaths) {
- for(index=0;index<numKeys;index++)
- if (ppPaths[index]) free(ppPaths[index]);
- free(ppPaths);
+ for(index=0; index<numKeys; index++)
+ PyMem_RawFree(ppPaths[index]);
+ PyMem_RawFree(ppPaths);
}
if (newKey)
RegCloseKey(newKey);
- if (keyBuf)
- free(keyBuf);
+ PyMem_RawFree(keyBuf);
return retval;
}
#endif /* Py_ENABLE_SHARED */
@@ -616,7 +615,7 @@ calculate_path(void)
if (envpath != NULL)
bufsz += wcslen(envpath) + 1;
- module_search_path = buf = malloc(bufsz*sizeof(wchar_t));
+ module_search_path = buf = PyMem_RawMalloc(bufsz*sizeof(wchar_t));
if (buf == NULL) {
/* We can't exit, so print a warning and limp along */
fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
@@ -629,10 +628,8 @@ calculate_path(void)
module_search_path = PYTHONPATH;
}
#ifdef MS_WINDOWS
- if (machinepath)
- free(machinepath);
- if (userpath)
- free(userpath);
+ PyMem_RawFree(machinepath);
+ PyMem_RawFree(userpath);
#endif /* MS_WINDOWS */
return;
}
@@ -652,13 +649,13 @@ calculate_path(void)
wcscpy(buf, userpath);
buf = wcschr(buf, L'\0');
*buf++ = DELIM;
- free(userpath);
+ PyMem_RawFree(userpath);
}
if (machinepath) {
wcscpy(buf, machinepath);
buf = wcschr(buf, L'\0');
*buf++ = DELIM;
- free(machinepath);
+ PyMem_RawFree(machinepath);
}
if (pythonhome == NULL) {
if (!skipdefault) {
@@ -745,7 +742,7 @@ void
Py_SetPath(const wchar_t *path)
{
if (module_search_path != NULL) {
- free(module_search_path);
+ PyMem_RawFree(module_search_path);
module_search_path = NULL;
}
if (path != NULL) {
@@ -753,10 +750,10 @@ Py_SetPath(const wchar_t *path)
wchar_t *prog = Py_GetProgramName();
wcsncpy(progpath, prog, MAXPATHLEN);
prefix[0] = L'\0';
- module_search_path = malloc((wcslen(path) + 1) * sizeof(wchar_t));
+ module_search_path = PyMem_RawMalloc((wcslen(path) + 1) * sizeof(wchar_t));
if (module_search_path != NULL)
wcscpy(module_search_path, path);
- }
+ }
}
wchar_t *