summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2015-03-05 12:48:47 -0800
committerJeremy Allison <jra@samba.org>2015-03-08 18:24:06 +0100
commit3289a5d84f73bf044e5767a6c47a3f7bf8357c08 (patch)
treeb231566d9d0082f792952f696a3af69ad9351935
parente53f6e9ec2eb05ded39a0caec407bb3bb23039cf (diff)
downloadsamba-3289a5d84f73bf044e5767a6c47a3f7bf8357c08.tar.gz
lib: talloc: Fix bug when calling a destructor.
If the destructor itself calls talloc_set_destructor() and returns -1, the new destructor set is overwritten by talloc. Dectect that and leave the new destructor in place. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ira Cooper <ira@samba.org>
-rw-r--r--lib/talloc/talloc.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index fa56ea56780..1ccb039ff74 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -991,7 +991,13 @@ static inline int _talloc_free_internal(void *ptr, const char *location)
}
tc->destructor = (talloc_destructor_t)-1;
if (d(ptr) == -1) {
- tc->destructor = d;
+ /*
+ * Only replace the destructor pointer if
+ * calling the destructor didn't modify it.
+ */
+ if (tc->destructor == (talloc_destructor_t)-1) {
+ tc->destructor = d;
+ }
return -1;
}
tc->destructor = NULL;