diff -up at-spi2-atk-2.22.0/atk-adaptor/adaptors/accessible-adaptor.c.invalid-write at-spi2-atk-2.22.0/atk-adaptor/adaptors/accessible-adaptor.c
--- at-spi2-atk-2.22.0/atk-adaptor/adaptors/accessible-adaptor.c.invalid-write	2017-04-25 08:26:26.399992793 +0200
+++ at-spi2-atk-2.22.0/atk-adaptor/adaptors/accessible-adaptor.c	2017-04-25 08:32:47.460987524 +0200
@@ -182,7 +182,8 @@ impl_GetChildAtIndex (DBusConnection * b
     }
   child = atk_object_ref_accessible_child (object, i);
   reply = spi_object_return_reference (message, child);
-  g_object_unref (child);
+  if (child)
+    g_object_unref (child);
 
   return reply;
 }
diff -up at-spi2-atk-2.22.0/atk-adaptor/adaptors/collection-adaptor.c.invalid-write at-spi2-atk-2.22.0/atk-adaptor/adaptors/collection-adaptor.c
--- at-spi2-atk-2.22.0/atk-adaptor/adaptors/collection-adaptor.c.invalid-write	2017-04-25 08:27:29.087991926 +0200
+++ at-spi2-atk-2.22.0/atk-adaptor/adaptors/collection-adaptor.c	2017-04-25 08:32:43.580987577 +0200
@@ -494,9 +494,12 @@ sort_order_canonical (MatchRulePrivate *
     {
       AtkObject *child = atk_object_ref_accessible_child (obj, i);
 
-      g_object_unref (child);
+      if (!child)
+        break;
+
       if (prev && child == pobj)
         {
+          g_object_unref (child);
           return kount;
         }
 
@@ -517,6 +520,7 @@ sort_order_canonical (MatchRulePrivate *
         kount = sort_order_canonical (mrp, ls, kount,
                                       max, child, 0, TRUE,
                                       pobj, recurse, traverse);
+      g_object_unref (child);
     }
   return kount;
 }
@@ -559,19 +563,23 @@ sort_order_rev_canonical (MatchRulePriva
          and get it's last descendant.
          First, get the previous sibling */
       nextobj = atk_object_ref_accessible_child (parent, indexinparent - 1);
-      g_object_unref (nextobj);
 
       /* Now, drill down the right side to the last descendant */
-      while (atk_object_get_n_accessible_children (nextobj) > 0)
+      while (nextobj && atk_object_get_n_accessible_children (nextobj) > 0)
         {
-          nextobj = atk_object_ref_accessible_child (nextobj,
+	  AtkObject *follow;
+
+          follow = atk_object_ref_accessible_child (nextobj,
                                                      atk_object_get_n_accessible_children
                                                      (nextobj) - 1);
           g_object_unref (nextobj);
+	  nextobj = follow;
         }
       /* recurse with the last descendant */
       kount = sort_order_rev_canonical (mrp, ls, kount, max,
                                         nextobj, TRUE, pobj);
+      if (nextobj)
+	 g_object_unref (nextobj);
     }
   else if (max == 0 || kount < max)
     {
s