[PATCH 2/3] TODO: talloc: talloc_free() should remove the reference to the current owner

Sam Liddicott sam at liddicott.com
Thu Jan 15 14:01:15 GMT 2009


[this is metzes wip:
http://gitweb.samba.org/?p=metze/samba/wip.git;a=commitdiff_plain;h=8e2aefad84ffd5b96101645650bdfe6a9bb26d2b]

TODO: talloc: talloc_free() should remove the reference to the current owner

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

metze
---
 lib/talloc/talloc.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index 1f7e524..350150f 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -494,9 +494,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;
 	}


More information about the samba-technical mailing list