bpo-31095: fix potential crash during GC (GH-3195)

(cherry picked from commit a6296d34a478b4f697ea9db798146195075d496c)
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index b78a0fc..212211c 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -512,6 +512,8 @@
 static void
 ast_dealloc(AST_object *self)
 {
+    /* bpo-31095: UnTrack is needed before calling any callbacks */
+    PyObject_GC_UnTrack(self);
     Py_CLEAR(self->dict);
     Py_TYPE(self)->tp_free(self);
 }