Issue #16447: Fix potential segfault when setting __name__ on a class.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 9f89972..6ece741 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -298,10 +298,13 @@
 
     Py_INCREF(value);
 
-    Py_DECREF(et->ht_name);
+    /* Wait until et is a sane state before Py_DECREF'ing the old et->ht_name
+       value.  (Bug #16447.)  */
+    tmp = et->ht_name;
     et->ht_name = value;
 
     type->tp_name = tp_name;
+    Py_DECREF(tmp);
 
     return 0;
 }