bpo-30547: Fix multiple reference leaks (#1995)
Fix regressions introduced by:
- bpo-22257: commits 1abcf6700b4da6207fe859de40c6c1bada6b4fec and 6b4be195cd8868b76eb6fbe166acc39beee8ce36
Co-Authored-By: Victor Stinner <victor.stinner@gmail.com>
Co-Authored-By: Louie Lu <git@louie.lu>
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 048c2b2..ec26824 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -302,9 +302,11 @@
/* Install importlib as the implementation of import */
value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod);
- if (value != NULL)
+ if (value != NULL) {
+ Py_DECREF(value);
value = PyObject_CallMethod(importlib,
"_install_external_importers", "");
+ }
if (value == NULL) {
PyErr_Print();
Py_FatalError("Py_Initialize: importlib install failed");
@@ -325,6 +327,7 @@
PyErr_Print();
Py_FatalError("Py_EndInitialization: external importer setup failed");
}
+ Py_DECREF(value);
}