summaryrefslogtreecommitdiff
path: root/source4/lib/talloc/talloc.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-01-02 12:55:33 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:08:10 -0500
commitf4b349127bdfe233476fe2efba961912f39a5cbd (patch)
tree8b612fc9b60c9e253964c0d539e071dd7e0afe28 /source4/lib/talloc/talloc.c
parent09a76e204cf339862f8b0b45979d65cc34aa3c36 (diff)
downloadsamba-f4b349127bdfe233476fe2efba961912f39a5cbd.tar.gz
samba-f4b349127bdfe233476fe2efba961912f39a5cbd.tar.bz2
samba-f4b349127bdfe233476fe2efba961912f39a5cbd.zip
r4479: added the function talloc_autofree_context() which returns a talloc context that
will automatically be freed on program exit. This is useful for reducing clutter in leak reports (This used to be commit cf73dda652e0a121901f22771104be6751c0fcb9)
Diffstat (limited to 'source4/lib/talloc/talloc.c')
-rw-r--r--source4/lib/talloc/talloc.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c
index 4666e28288..9e8868191f 100644
--- a/source4/lib/talloc/talloc.c
+++ b/source4/lib/talloc/talloc.c
@@ -67,6 +67,7 @@
NULL
*/
static const void *null_context;
+static void *cleanup_context;
struct talloc_reference_handle {
@@ -1004,3 +1005,23 @@ void *talloc_realloc_fn(const void *context, void *ptr, size_t size)
{
return _talloc_realloc(context, ptr, size, NULL);
}
+
+
+static void talloc_autofree(void)
+{
+ talloc_free(cleanup_context);
+ cleanup_context = NULL;
+}
+
+/*
+ return a context which will be auto-freed on exit
+ this is useful for reducing the noise in leak reports
+*/
+void *talloc_autofree_context(void)
+{
+ if (cleanup_context == NULL) {
+ cleanup_context = talloc_named_const(NULL, 0, "autofree_context");
+ atexit(talloc_autofree);
+ }
+ return cleanup_context;
+}