File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2666,13 +2666,22 @@ sys__clear_type_descriptors(PyObject *module, PyObject *type)
26662666 return NULL ;
26672667 }
26682668 PyObject * dict = _PyType_GetDict (typeobj );
2669- if (PyDict_PopString (dict , "__dict__" , NULL ) < 0 ) {
2669+ PyObject * dunder_dict = NULL ;
2670+ if (PyDict_PopString (dict , "__dict__" , & dunder_dict ) < 0 ) {
26702671 return NULL ;
26712672 }
2672- if (PyDict_PopString (dict , "__weakref__" , NULL ) < 0 ) {
2673+ PyObject * dunder_weakref = NULL ;
2674+ if (PyDict_PopString (dict , "__weakref__" , & dunder_weakref ) < 0 ) {
2675+ PyType_Modified (typeobj );
2676+ Py_XDECREF (dunder_dict );
26732677 return NULL ;
26742678 }
26752679 PyType_Modified (typeobj );
2680+ // We try to hold onto a reference to these until after we call
2681+ // PyType_Modified(), in case their deallocation triggers somer user code
2682+ // that tries to do something to the type.
2683+ Py_XDECREF (dunder_dict );
2684+ Py_XDECREF (dunder_weakref );
26762685 Py_RETURN_NONE ;
26772686}
26782687
You can’t perform that action at this time.
0 commit comments