mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-115649: Copy the filename into main interpreter before intern in import.c (#120315)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
95737bbf18
commit
28140d1f2d
2 changed files with 13 additions and 1 deletions
|
@ -1969,7 +1969,17 @@ import_run_extension(PyThreadState *tstate, PyModInitFunction p0,
|
|||
if (info->filename != NULL) {
|
||||
// XXX There's a refleak somewhere with the filename.
|
||||
// Until we can track it down, we intern it.
|
||||
PyObject *filename = Py_NewRef(info->filename);
|
||||
PyObject *filename = NULL;
|
||||
if (switched) {
|
||||
// The original filename may be allocated by subinterpreter's
|
||||
// obmalloc, so we create a copy here.
|
||||
filename = _PyUnicode_Copy(info->filename);
|
||||
if (filename == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
filename = Py_NewRef(info->filename);
|
||||
}
|
||||
PyUnicode_InternInPlace(&filename);
|
||||
if (PyModule_AddObjectRef(mod, "__file__", filename) < 0) {
|
||||
PyErr_Clear(); /* Not important enough to report */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue