8000 bpo-1635741: Fix winreg reference leaks (GH-31560) · python/cpython@c6d0b5e · GitHub
[go: up one dir, main page]

Skip to content

Commit c6d0b5e

Browse files
vstinnerasvetlov
authored andcommitted
bpo-1635741: Fix winreg reference leaks (GH-31560)
Clear also the PyHKEY_Type static type at exit.
1 parent 146079d commit c6d0b5e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Objects/object.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,11 @@ _PyTypes_InitState(PyInterpreterState *interp)
18251825
}
18261826

18271827

1828+
1829+
#ifdef MS_WINDOWS
1830+
extern PyTypeObject PyHKEY_Type;
1831+
#endif
1832+
18281833
static PyTypeObject* static_types[] = {
18291834
// The two most important base types: must be initialized first and
18301835
// deallocated last.
@@ -1869,6 +1874,9 @@ static PyTypeObject* static_types[] = {
18691874
&PyFunction_Type,
18701875
&PyGen_Type,
18711876
&PyGetSetDescr_Type,
1877+
#ifdef MS_WINDOWS
1878+
&PyHKEY_Type,
1879+
#endif
18721880
&PyInstanceMethod_Type,
18731881
&PyListIter_Type,
18741882
&PyListRevIter_Type,

PC/winreg.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,11 +2046,9 @@ PyMODINIT_FUNC PyInit_winreg(void)
20462046
PyHKEY_Type.tp_doc = PyHKEY_doc;
20472047
if (PyType_Ready(&PyHKEY_Type) < 0)
20482048
return NULL;
2049-
Py_INCREF(&PyHKEY_Type);
20502049
if (PyDict_SetItemString(d, "HKEYType",
20512050
(PyObject *)&PyHKEY_Type) != 0)
20522051
return NULL;
2053-
Py_INCREF(PyExc_OSError);
20542052
if (PyDict_SetItemString(d, "error",
20552053
PyExc_OSError) != 0)
20562054
return NULL;
@@ -2116,5 +2114,3 @@ PyMODINIT_FUNC PyInit_winreg(void)
21162114
ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
21172115
return m;
21182116
}
2119-
2120-

0 commit comments

Comments
 (0)
0