@@ -7004,10 +7004,14 @@ update_all_slots(PyTypeObject* type)
70047004static int
70057005set_names (PyTypeObject * type )
70067006{
7007- PyObject * key , * value , * set_name , * tmp ;
7007+ PyObject * names_to_set , * key , * value , * set_name , * tmp ;
70087008 Py_ssize_t i = 0 ;
70097009
7010- while (PyDict_Next (type -> tp_dict , & i , & key , & value )) {
7010+ names_to_set = PyDict_Copy (type -> tp_dict );
7011+ if (names_to_set == NULL )
7012+ return -1 ;
7013+
7014+ while (PyDict_Next (names_to_set , & i , & key , & value )) {
70117015 set_name = lookup_maybe (value , & PyId___set_name__ );
70127016 if (set_name != NULL ) {
70137017 tmp = PyObject_CallFunctionObjArgs (set_name , type , key , NULL );
@@ -7017,15 +7021,19 @@ set_names(PyTypeObject *type)
70177021 "Error calling __set_name__ on '%.100s' instance %R "
70187022 "in '%.100s'" ,
70197023 value -> ob_type -> tp_name , key , type -> tp_name );
7024+ Py_DECREF (names_to_set );
70207025 return -1 ;
70217026 }
70227027 else
70237028 Py_DECREF (tmp );
70247029 }
7025- else if (PyErr_Occurred ())
7030+ else if (PyErr_Occurred ()) {
7031+ Py_DECREF (names_to_set );
70267032 return -1 ;
7033+ }
70277034 }
70287035
7036+ Py_DECREF (names_to_set );
70297037 return 0 ;
70307038}
70317039
0 commit comments