summaryrefslogtreecommitdiff
path: root/source4/lib/talloc/talloc.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-09-29 10:50:12 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:20:27 -0500
commit4ccdd5370416a90088ad5a5879eca5f7cb1161a4 (patch)
tree25c55db612315bed0a2564ebbbfd6d5c17f8af5d /source4/lib/talloc/talloc.c
parentaeee137f802462574aad1b90830dcd2264566e2e (diff)
downloadsamba-4ccdd5370416a90088ad5a5879eca5f7cb1161a4.tar.gz
samba-4ccdd5370416a90088ad5a5879eca5f7cb1161a4.tar.bz2
samba-4ccdd5370416a90088ad5a5879eca5f7cb1161a4.zip
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)
Diffstat (limited to 'source4/lib/talloc/talloc.c')
-rw-r--r--source4/lib/talloc/talloc.c18
1 files changed, 12 insertions, 6 deletions
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)