summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-17 17:00:26 (GMT)
committerGitHub <noreply@github.com>2024-06-17 17:00:26 (GMT)
commit9172bc35c669b7706d7122d4f0a90f065700a474 (patch)
tree59576ed22bacb8d28d01b213bf74074055a58d12 /Python
parentf7ba3233a2b6cd6e19c47253d8ab627cd1802ca8 (diff)
downloadcpython-9172bc35c669b7706d7122d4f0a90f065700a474.zip
cpython-9172bc35c669b7706d7122d4f0a90f065700a474.tar.gz
cpython-9172bc35c669b7706d7122d4f0a90f065700a474.tar.bz2
[3.13] gh-115649: Copy the filename into main interpreter before intern in import.c (GH-120315) (#120652)
gh-115649: Copy the filename into main interpreter before intern in import.c (GH-120315) (cherry picked from commit 28140d1f2da1766bfbb83f58779f15255c73c871) Co-authored-by: AN Long <aisk@users.noreply.github.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c
index 10ac49f..8cf97b5 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 */