gh-112564: Fix UAF for gc debug print (gh-160662)

Fix a crash in the garbage collector when gc.DEBUG_COLLECTABLE or
gc.DEBUG_UNCOLLECTABLE is set and writing the debug output to
sys.stderr frees one of the objects being reported.
2 files changed