diff options
author | Jeremy Allison <jra@samba.org> | 2015-03-05 12:48:47 -0800 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2015-03-15 22:14:08 +0100 |
commit | 8194d069e55914710656abc8fb9d16a1fb24eb1c (patch) | |
tree | 2e042a7e99b2b17a5e468d8fc1ea1a183bc32f3d | |
parent | 6640cfa7594c2e3897d2186d5f0345cdeb11d987 (diff) | |
download | samba-8194d069e55914710656abc8fb9d16a1fb24eb1c.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>
(cherry picked from commit 3289a5d84f73bf044e5767a6c47a3f7bf8357c08)
-rw-r--r-- | lib/talloc/talloc.c | 8 |
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; |