lib: talloc: Allow destructors to reparent the object they're called on.
commita21e4e2873794a80f8fb6e0e340be4ce6d327c33
authorJeremy Allison <jra@samba.org>
Wed, 4 Mar 2015 01:02:47 +0000 (3 17:02 -0800)
committerKarolin Seeger <kseeger@samba.org>
Tue, 24 Mar 2015 03:51:14 +0000 (24 04:51 +0100)
treecff21d2a04cf1f79c4d8bc987a40df619607083d
parent599ca101656d1111ff7aec32d1a813ef434d9977
lib: talloc: Allow destructors to reparent the object they're called on.

If a destructor returns failure (-1) when freeing a child, talloc
must then reparent the child.

Firstly it tries the owner of any reference, next the parent of the
current object calling _talloc_free_children_internal(), and finally
the null context in the last resort.

If a destructor reparented its own object, which can be a very
desirable thing to do (a destructor can make a decision it isn't
time to die yet, and as the parent may be going away it might
want to move itself to longer-term storage) then this new parent
gets overwritten by the existing reparenting logic.

This patch checks when freeing a child if it already reparented
itself, and if it did doesn't then overwrite the new parent.

Makes destructors more flexible.

Needed for bug:

https://bugzilla.samba.org/show_bug.cgi?id=11144

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ira Cooper <ira@samba.org>
lib/talloc/talloc.c