Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Work around a refleak.
  • Loading branch information
ericsnowcurrently committed May 7, 2024
commit 0b16f3fb21d3c328259afe100e9a0ab762c646a6
9 changes: 5 additions & 4 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,9 +1147,6 @@ init_cached_m_dict(struct extensions_cache_value *value, PyObject *m_dict)
return -1;
}
// XXX We may want to make the copy immortal.
// XXX This incref shouldn't be necessary. We are decref'ing
// one to many times somewhere.
Py_INCREF(copied);

value->_m_dict = (struct cached_m_dict){
.copied=copied,
Expand Down Expand Up @@ -1973,7 +1970,11 @@ import_run_extension(PyThreadState *tstate, PyModInitFunction p0,
if (res.kind == _Py_ext_module_kind_SINGLEPHASE) {
/* Remember the filename as the __file__ attribute */
if (info->filename != NULL) {
if (PyModule_AddObjectRef(mod, "__file__", info->filename) < 0) {
// XXX There's a refleak somewhere with the filename.
// Until we can track it down, we intern it.
PyObject *filename = Py_NewRef(info->filename);
PyUnicode_InternInPlace(&filename);
if (PyModule_AddObjectRef(mod, "__file__", filename) < 0) {
PyErr_Clear(); /* Not important enough to report */
}
}
Expand Down