need_new_parent = true;
}
+ /*
+ * If we have not found a parent yet, but we need one
+ * we try to find a parent that is not within
+ * _talloc_free_internal() itself
+ * (indicated by TALLOC_FLAG_LOOP).
+ */
if (unlikely(need_new_parent && new_parent == NULL)) {
+ struct talloc_chunk *parent_tc;
+
if (only_children) {
new_parent = ptr;
+ parent_tc = NULL;
} else {
- new_parent = talloc_parent(ptr);
+ parent_tc = talloc_parent_chunk(ptr);
+ }
+
+ while (parent_tc) {
+ const void *parent = TC_PTR_FROM_CHUNK(parent_tc);
+ if (parent_tc->flags & TALLOC_FLAG_LOOP) {
+ parent_tc = talloc_parent_chunk(parent);
+ continue;
+ }
+
+ new_parent = parent;
+ break;
}
}