bpo-30860: Fix a refleak. (#3506)
* Drop warnoptions from PyInterpreterState.
* Drop xoptions from PyInterpreterState.
* Don't set warnoptions and _xoptions again.
* Decref after adding to sys.__dict__.
* Drop an unused macro.
* Check sys.xoptions *before* we delete it.
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index caa324e..3265d70 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1006,6 +1006,11 @@
while (_PyGC_CollectIfEnabled() > 0)
/* nothing */;
#endif
+
+#ifdef Py_REF_DEBUG
+ PyObject *showrefcount = _PyDebug_XOptionShowRefCount();
+#endif
+
/* Destroy all modules */
PyImport_Cleanup();
@@ -1053,7 +1058,10 @@
/* dump hash stats */
_PyHash_Fini();
- _PY_DEBUG_PRINT_TOTAL_REFS();
+#ifdef Py_REF_DEBUG
+ if (showrefcount == Py_True)
+ _PyDebug_PrintTotalRefs();
+#endif
#ifdef Py_TRACE_REFS
/* Display all objects still alive -- this can invoke arbitrary