From 0b702df708b9496ab6408d1bb6a789f44c3bb82b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 5 Mar 2015 12:48:47 -0800 Subject: [PATCH] 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 Reviewed-by: Ira Cooper (cherry picked from commit 3289a5d84f73bf044e5767a6c47a3f7bf8357c08) --- lib/talloc/talloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index fa56ea567806..1ccb039ff744 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; -- 2.34.1