summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-07 14:25:15 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-07 14:25:15 (GMT)
commit1a7425f67a0d141483d89ca80ca01e3cb7f6be92 (patch)
treec5c3db81a3f0b754d3c7d2cfafd8609cba58142a /Modules/main.c
parent51fa458d0a8fa6e9f583fc5a1c4164080093e763 (diff)
downloadcpython-1a7425f67a0d141483d89ca80ca01e3cb7f6be92.zip
cpython-1a7425f67a0d141483d89ca80ca01e3cb7f6be92.tar.gz
cpython-1a7425f67a0d141483d89ca80ca01e3cb7f6be92.tar.bz2
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 'Modules/main.c')
-rw-r--r--Modules/main.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/Modules/main.c b/Modules/main.c
index 2daefb8..2bafbfd 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -391,7 +391,7 @@ Py_Main(int argc, wchar_t **argv)
command to interpret. */
len = wcslen(_PyOS_optarg) + 1 + 1;
- command = (wchar_t *)malloc(sizeof(wchar_t) * len);
+ command = (wchar_t *)PyMem_RawMalloc(sizeof(wchar_t) * len);
if (command == NULL)
Py_FatalError(
"not enough memory to copy -c argument");
@@ -520,7 +520,7 @@ Py_Main(int argc, wchar_t **argv)
*wp != L'\0') {
wchar_t *buf, *warning;
- buf = (wchar_t *)malloc((wcslen(wp) + 1) * sizeof(wchar_t));
+ buf = (wchar_t *)PyMem_RawMalloc((wcslen(wp) + 1) * sizeof(wchar_t));
if (buf == NULL)
Py_FatalError(
"not enough memory to copy PYTHONWARNINGS");
@@ -530,7 +530,7 @@ Py_Main(int argc, wchar_t **argv)
warning = wcstok(NULL, L",")) {
PySys_AddWarnOption(warning);
}
- free(buf);
+ PyMem_RawFree(buf);
}
#else
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
@@ -539,7 +539,7 @@ Py_Main(int argc, wchar_t **argv)
/* settle for strtok here as there's no one standard
C89 wcstok */
- buf = (char *)malloc(strlen(p) + 1);
+ buf = (char *)PyMem_RawMalloc(strlen(p) + 1);
if (buf == NULL)
Py_FatalError(
"not enough memory to copy PYTHONWARNINGS");
@@ -563,7 +563,7 @@ Py_Main(int argc, wchar_t **argv)
}
setlocale(LC_ALL, oldloc);
free(oldloc);
- free(buf);
+ PyMem_RawFree(buf);
}
#endif
@@ -633,7 +633,7 @@ Py_Main(int argc, wchar_t **argv)
wchar_t* buffer;
size_t len = strlen(p) + 1;
- buffer = malloc(len * sizeof(wchar_t));
+ buffer = PyMem_RawMalloc(len * sizeof(wchar_t));
if (buffer == NULL) {
Py_FatalError(
"not enough memory to copy PYTHONEXECUTABLE");
@@ -707,7 +707,7 @@ Py_Main(int argc, wchar_t **argv)
if (command) {
sts = run_command(command, &cf);
- free(command);
+ PyMem_RawFree(command);
} else if (module) {
sts = (RunModule(module, 1) != 0);
}