add_object_array_with_mode_context(obj, name, array, S_IFINVALID, context);
 }
 
+/*
+ * Free all memory associated with an entry; the result is
+ * in an unspecified state and should not be examined.
+ */
+static void object_array_release_entry(struct object_array_entry *ent)
+{
+       if (ent->name != object_array_slopbuf)
+               free(ent->name);
+}
+
 void object_array_filter(struct object_array *array,
                         object_array_each_func_t want, void *cb_data)
 {
                                objects[dst] = objects[src];
                        dst++;
                } else {
-                       if (objects[src].name != object_array_slopbuf)
-                               free(objects[src].name);
+                       object_array_release_entry(&objects[src]);
                }
        }
        array->nr = dst;
                                objects[array->nr] = objects[src];
                        array->nr++;
                } else {
-                       if (objects[src].name != object_array_slopbuf)
-                               free(objects[src].name);
+                       object_array_release_entry(&objects[src]);
                }
        }
 }