[Python-checkins] bpo-1635741: Fix winreg reference leaks (GH-31560)
vstinner
webhook-mailer at python.org
Fri Feb 25 06:34:18 EST 2022
https://github.com/python/cpython/commit/4657bf701670215ce69b89401b2307022a3b0a7d
commit: 4657bf701670215ce69b89401b2307022a3b0a7d
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-02-25T12:34:00+01:00
summary:
bpo-1635741: Fix winreg reference leaks (GH-31560)
Clear also the PyHKEY_Type static type at exit.
files:
M Objects/object.c
M PC/winreg.c
diff --git a/Objects/object.c b/Objects/object.c
index 3044c862fb9da..77a457223764a 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1825,6 +1825,11 @@ _PyTypes_InitState(PyInterpreterState *interp)
}
+
+#ifdef MS_WINDOWS
+extern PyTypeObject PyHKEY_Type;
+#endif
+
static PyTypeObject* static_types[] = {
// The two most important base types: must be initialized first and
// deallocated last.
@@ -1869,6 +1874,9 @@ static PyTypeObject* static_types[] = {
&PyFunction_Type,
&PyGen_Type,
&PyGetSetDescr_Type,
+#ifdef MS_WINDOWS
+ &PyHKEY_Type,
+#endif
&PyInstanceMethod_Type,
&PyListIter_Type,
&PyListRevIter_Type,
diff --git a/PC/winreg.c b/PC/winreg.c
index 004a89a5355f6..2d44c82000c68 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -2046,11 +2046,9 @@ PyMODINIT_FUNC PyInit_winreg(void)
PyHKEY_Type.tp_doc = PyHKEY_doc;
if (PyType_Ready(&PyHKEY_Type) < 0)
return NULL;
- Py_INCREF(&PyHKEY_Type);
if (PyDict_SetItemString(d, "HKEYType",
(PyObject *)&PyHKEY_Type) != 0)
return NULL;
- Py_INCREF(PyExc_OSError);
if (PyDict_SetItemString(d, "error",
PyExc_OSError) != 0)
return NULL;
@@ -2116,5 +2114,3 @@ PyMODINIT_FUNC PyInit_winreg(void)
ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
return m;
}
-
-
More information about the Python-checkins
mailing list