DISCUSS:COMPLEX FIX talloc: _talloc_free_children_internal more complex search for...
authorStefan Metzmacher <metze@samba.org>
Fri, 8 Apr 2011 11:13:50 +0000 (13:13 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 17 May 2018 08:15:17 +0000 (10:15 +0200)
This needs a lot of discussion...
- maybe only if child->destructor...?

metze

lib/talloc/talloc.c

index 2d87069750adbed4b2ccc49abffdf5f6922b4762..4c00b23aaf899940882df0e64a7ad4cd7d6f3c2b 100644 (file)
@@ -1698,11 +1698,31 @@ static inline void _tc_free_children_internal(struct talloc_chunk *tc,
                        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;
                        }
                }