TODO: talloc: talloc_free() should remove the reference to the current owner
authorStefan Metzmacher <metze@samba.org>
Tue, 13 Jan 2009 15:09:27 +0000 (16:09 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 17 May 2018 08:15:19 +0000 (10:15 +0200)
The parent of the first reference becomes the owner...

metze

lib/talloc/talloc.c

index 4c00b23aaf899940882df0e64a7ad4cd7d6f3c2b..7e48cf1bbf1246404f0033eaae26b06039795bf6 100644 (file)
@@ -1103,9 +1103,13 @@ static inline int _tc_free_internal(struct talloc_chunk *tc,
                 * pointer.
                 */
                is_child = talloc_is_parent(tc->refs, ptr);
-               _talloc_free_internal(tc->refs, location);
                if (is_child) {
+                       _talloc_free_internal(tc->refs, location);
                        return _talloc_free_internal(ptr, location);
+               } else {
+                       /* the first reference becomes the owner */
+                       _talloc_steal(talloc_parent(tc->refs), ptr);
+                       _talloc_free_internal(tc->refs, location);
                }
                return -1;
        }