diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-04 16:33:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 16:33:06 (GMT) |
commit | 58ca33b4674f39189b03c9a39fa7b676b43b3d08 (patch) | |
tree | fa25afd9e677de7e2c113816ae199551240a4158 /Python/importdl.c | |
parent | 18ce7f1d0a3d65f34f25c5964da588743a1bfe3c (diff) | |
download | cpython-58ca33b4674f39189b03c9a39fa7b676b43b3d08.zip cpython-58ca33b4674f39189b03c9a39fa7b676b43b3d08.tar.gz cpython-58ca33b4674f39189b03c9a39fa7b676b43b3d08.tar.bz2 |
bpo-1635741: Fix ref leak in _PyWarnings_Init() error path (GH-23151)
Replace PyModule_AddObject() with PyModule_AddObjectRef() in the
_warnings module to fix a reference leak on error.
Use also PyModule_AddObjectRef() in importdl.c.
Diffstat (limited to 'Python/importdl.c')
-rw-r--r-- | Python/importdl.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Python/importdl.c b/Python/importdl.c index fbeb9fb..1847eba 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -220,10 +220,9 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) def->m_base.m_init = p0; /* Remember the filename as the __file__ attribute */ - if (PyModule_AddObject(m, "__file__", path) < 0) + if (PyModule_AddObjectRef(m, "__file__", path) < 0) { PyErr_Clear(); /* Not important enough to report */ - else - Py_INCREF(path); + } PyObject *modules = PyImport_GetModuleDict(); if (_PyImport_FixupExtensionObject(m, name_unicode, path, modules) < 0) |