diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-04 17:33:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 17:33:06 +0100 |
commit | 58ca33b4674f39189b03c9a39fa7b676b43b3d08 (patch) | |
tree | fa25afd9e677de7e2c113816ae199551240a4158 /Python/_warnings.c | |
parent | 18ce7f1d0a3d65f34f25c5964da588743a1bfe3c (diff) | |
download | cpython-git-58ca33b4674f39189b03c9a39fa7b676b43b3d08.tar.gz |
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/_warnings.c')
-rw-r--r-- | Python/_warnings.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index 3c048af419..e42b7c3be3 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -1395,18 +1395,13 @@ _PyWarnings_Init(void) goto error; } - Py_INCREF(st->filters); - if (PyModule_AddObject(m, "filters", st->filters) < 0) { + if (PyModule_AddObjectRef(m, "filters", st->filters) < 0) { goto error; } - - Py_INCREF(st->once_registry); - if (PyModule_AddObject(m, "_onceregistry", st->once_registry) < 0) { + if (PyModule_AddObjectRef(m, "_onceregistry", st->once_registry) < 0) { goto error; } - - Py_INCREF(st->default_action); - if (PyModule_AddObject(m, "_defaultaction", st->default_action) < 0) { + if (PyModule_AddObjectRef(m, "_defaultaction", st->default_action) < 0) { goto error; } |