gh-105375: Harden error handling in _testcapi/heaptype.c
#105608
Merged
_testcapi/heaptype.c
#105608