[issue11320] Usage of API method Py_SetPath causes errors in Py_Initialize() (Posix ony))
Antoine Pitrou
report at bugs.python.org
Fri Mar 18 00:31:54 CET 2011
Antoine Pitrou <pitrou at free.fr> added the comment:
Ok, the issue here is that you can't call Py_SetPath() on the point returned by Py_GetPath(), since the memory refered to that pointer is free()d at the beginning of Py_SetPath(). The following works, though:
main(int argc, char **argv)
{
wchar_t *path, *newpath;
path = Py_GetPath();
newpath = malloc((wcslen(path) + 1) * sizeof(wchar_t));
wcscpy(newpath, path);
Py_SetPath(newpath);
free(newpath);
printf("Init\n");
Py_Initialize();
printf("-- END\n");
}
Perhaps we could modify Py_SetPath() so that it copies the new path first before deallocating the old one, but I'm not sure I see the point of calling Py_SetPath() with the pointer returned by Py_GetPath().
----------
versions: +Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11320>
_______________________________________
More information about the Python-bugs-list
mailing list