gh-145202: Fix segfault in unicodedata.iter_graphemes when cleared by GC by gourijain029-del · Pull Request #145203 · python/cpython
This PR fixes a segmentation fault in unicodedata.iter_graphemes and its segment objects, which occurred when the objects were cleared by the garbage collector before being deallocated.
In Modules/unicodedata.c, both GraphemeBreakIterator and SegmentObject have tp_clear implementations that set their string references to NULL. However, their deallocators were using Py_DECREF instead of Py_XDECREF. This led to a crash if a GC cycle (or interpreter shutdown) cleared the objects before they reached the deallocation path.
I've updated GBI_dealloc and Segment_dealloc to use Py_XDECREF to safely handle these NULL references.
Fixes gh-145202.