From 4ccdd5370416a90088ad5a5879eca5f7cb1161a4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 29 Sep 2006 10:50:12 +0000 Subject: r18995: - fix bug 4078 - talloc_free(talloc_autofree_context()); should not result in a SIGABORT on exit - add a test for this, but this test can also pass in the standalone build and samba3, as samba4 uses talloc_autofree_context() metze (This used to be commit 2be48c1b033dceb9517826054b8ea97df2c94472) --- source4/lib/talloc/talloc.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'source4/lib/talloc/talloc.c') diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c index 58028a85b8..15b27c61ee 100644 --- a/source4/lib/talloc/talloc.c +++ b/source4/lib/talloc/talloc.c @@ -82,7 +82,7 @@ NULL */ static void *null_context; -static void *cleanup_context; +static void *autofree_context; struct talloc_reference_handle { struct talloc_reference_handle *next, *prev; @@ -1208,10 +1208,15 @@ void *talloc_realloc_fn(const void *context, void *ptr, size_t size) } +static int talloc_autofree_destructor(void *ptr) +{ + autofree_context = NULL; + return 0; +} + static void talloc_autofree(void) { - talloc_free(cleanup_context); - cleanup_context = NULL; + talloc_free(autofree_context); } /* @@ -1220,11 +1225,12 @@ static void talloc_autofree(void) */ void *talloc_autofree_context(void) { - if (cleanup_context == NULL) { - cleanup_context = talloc_named_const(NULL, 0, "autofree_context"); + if (autofree_context == NULL) { + autofree_context = talloc_named_const(NULL, 0, "autofree_context"); + talloc_set_destructor(autofree_context, talloc_autofree_destructor); atexit(talloc_autofree); } - return cleanup_context; + return autofree_context; } size_t talloc_get_size(const void *context) -- cgit