Issue #15142: Fix reference leak when deallocating instances of types created using PyType_FromSpec().
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 934d06f..54a990e 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2387,6 +2387,12 @@
             res->ht_type.tp_doc = tp_doc;
         }
     }
+    if (res->ht_type.tp_dealloc == NULL) {
+        /* It's a heap type, so needs the heap types' dealloc.
+           subtype_dealloc will call the base type's tp_dealloc, if
+           necessary. */
+        res->ht_type.tp_dealloc = subtype_dealloc;
+    }
 
     if (PyType_Ready(&res->ht_type) < 0)
         goto fail;