diff options
author | AN Long <aisk@users.noreply.github.com> | 2024-06-17 15:57:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-17 15:57:22 (GMT) |
commit | 28140d1f2da1766bfbb83f58779f15255c73c871 (patch) | |
tree | e07c20792db7703f79675f9bf49447b8ecd46c77 /Python | |
parent | 95737bbf18765a24b6585708588c9b707dc30d27 (diff) | |
download | cpython-28140d1f2da1766bfbb83f58779f15255c73c871.zip cpython-28140d1f2da1766bfbb83f58779f15255c73c871.tar.gz cpython-28140d1f2da1766bfbb83f58779f15255c73c871.tar.bz2 |
gh-115649: Copy the filename into main interpreter before intern in import.c (#120315)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c index 2c7a461..9328819 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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 */ |