Skip to content

Commit

Permalink
bpo-1635741: Fix winreg reference leaks (GH-31560)
Browse files Browse the repository at this point in the history
Clear also the PyHKEY_Type static type at exit.
  • Loading branch information
vstinner authored and asvetlov committed Feb 26, 2022
1 parent 146079d commit c6d0b5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions PC/winreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2116,5 +2114,3 @@ PyMODINIT_FUNC PyInit_winreg(void)
ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
return m;
}


0 comments on commit c6d0b5e

Please sign in to comment.