TODO: talloc: talloc_free() should remove the reference to the current owner
authorStefan Metzmacher <metze@samba.org>
Mon, 2 Feb 2009 12:12:07 +0000 (12:12 +0000)
committerStefan Metzmacher <metze@samba.org>
Mon, 13 Jul 2009 18:54:30 +0000 (20:54 +0200)
TODO: talloc: talloc_free() should remove the reference to the current owner

The parent of the first reference becomes the owner...

metze

Signed-off-by: Sam Liddicott <sam@liddicott.com>
lib/talloc/talloc.c

index a1b158a42cd129674d1d0854ce43a96638853edb..d5b0c3bfe53252d06ed0215515d2fcb3bf1f44fd 100644 (file)
@@ -510,9 +510,13 @@ static inline int _talloc_free(void *ptr)
                 * pointer.
                 */
                is_child = talloc_is_parent(tc->refs, ptr);
-               _talloc_free(tc->refs);
                if (is_child) {
+                       _talloc_free(tc->refs);
                        return _talloc_free(ptr);
+               } else {
+                       /* the first reference becomes the owner */
+                       _talloc_steal(talloc_parent(tc->refs), ptr);
+                       _talloc_free(tc->refs);
                }
                return -1;
        }