summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-09-24 15:44:15 (GMT)
committerGitHub <noreply@github.com>2019-09-24 15:44:15 (GMT)
commit1ce152a42eaa917d7763bce93f1e1ca72530d7ca (patch)
treee6a43ecd6f9d776571f96544f763b016cf8047a9 /Python
parentb0e1ae5f5430433766e023c1a6936aeba0f2b84e (diff)
downloadcpython-1ce152a42eaa917d7763bce93f1e1ca72530d7ca.zip
cpython-1ce152a42eaa917d7763bce93f1e1ca72530d7ca.tar.gz
cpython-1ce152a42eaa917d7763bce93f1e1ca72530d7ca.tar.bz2
bpo-38234: Py_SetPath() uses the program full path (GH-16357)
Py_SetPath() now sets sys.executable to the program full path (Py_GetProgramFullPath()), rather than to the program name (Py_GetProgramName()). Fix also memory leaks in pathconfig_set_from_config().
Diffstat (limited to 'Python')
-rw-r--r--Python/pathconfig.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
index 7677a15..8f76fa5 100644
--- a/Python/pathconfig.c
+++ b/Python/pathconfig.c
@@ -23,6 +23,7 @@ wchar_t *_Py_dll_path = NULL;
static int
copy_wstr(wchar_t **dst, const wchar_t *src)
{
+ assert(*dst == NULL);
if (src != NULL) {
*dst = _PyMem_RawWcsdup(src);
if (*dst == NULL) {
@@ -172,6 +173,7 @@ pathconfig_set_from_config(_PyPathConfig *pathconfig, const PyConfig *config)
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
if (config->module_search_paths_set) {
+ PyMem_RawFree(pathconfig->module_search_path);
pathconfig->module_search_path = _PyWideStringList_Join(&config->module_search_paths, DELIM);
if (pathconfig->module_search_path == NULL) {
goto no_memory;
@@ -180,6 +182,8 @@ pathconfig_set_from_config(_PyPathConfig *pathconfig, const PyConfig *config)
#define COPY_CONFIG(PATH_ATTR, CONFIG_ATTR) \
if (config->CONFIG_ATTR) { \
+ PyMem_RawFree(pathconfig->PATH_ATTR); \
+ pathconfig->PATH_ATTR = NULL; \
if (copy_wstr(&pathconfig->PATH_ATTR, config->CONFIG_ATTR) < 0) { \
goto no_memory; \
} \
@@ -455,16 +459,15 @@ Py_SetPath(const wchar_t *path)
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
- /* Getting the program name calls pathconfig_global_init() */
- wchar_t *program_name = _PyMem_RawWcsdup(Py_GetProgramName());
+ /* Getting the program full path calls pathconfig_global_init() */
+ wchar_t *program_full_path = _PyMem_RawWcsdup(Py_GetProgramFullPath());
PyMem_RawFree(_Py_path_config.program_full_path);
PyMem_RawFree(_Py_path_config.prefix);
PyMem_RawFree(_Py_path_config.exec_prefix);
PyMem_RawFree(_Py_path_config.module_search_path);
- /* Copy program_name to program_full_path */
- _Py_path_config.program_full_path = program_name;
+ _Py_path_config.program_full_path = program_full_path;
_Py_path_config.prefix = _PyMem_RawWcsdup(L"");
_Py_path_config.exec_prefix = _PyMem_RawWcsdup(L"");
_Py_path_config.module_search_path = _PyMem_RawWcsdup(path);