[issue46857] Python leaks one reference at exit on Windows

Jeremy Kloth report at bugs.python.org
Fri Feb 25 20:29:38 EST 2022


Jeremy Kloth <jeremy.kloth+python-tracker at gmail.com> added the comment:

Good news, the difference on Windows was easy enough to find, bad news total refs are now negative!

--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -3647,8 +3647,7 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod)

 #define INIT_ALIAS(NAME, TYPE) \
     do { \
-        Py_INCREF(PyExc_ ## TYPE); \
-        Py_XDECREF(PyExc_ ## NAME); \
+        Py_XSETREF(PyExc_ ## NAME, PyExc_ ## TYPE); \
         PyExc_ ## NAME = PyExc_ ## TYPE; \
         if (PyDict_SetItemString(mod_dict, # NAME, PyExc_ ## NAME)) { \
             return -1; \

As the PyExc_* aliases just deprecated names for PyExc_OSError, there is no need to increment their refcounts.  Or they could be decremented in Fini().  Or they could finally be removed entirely.

----------
nosy: +jkloth

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46857>
_______________________________________


More information about the Python-bugs-list mailing list