summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/dcom/common/tables.c10
-rw-r--r--source4/lib/registry/common/reg_interface.c2
-rw-r--r--source4/lib/talloc/talloc.c21
-rw-r--r--source4/lib/talloc/talloc.h1
-rw-r--r--source4/lib/talloc/talloc_guide.txt6
5 files changed, 36 insertions, 4 deletions
diff --git a/source4/lib/dcom/common/tables.c b/source4/lib/dcom/common/tables.c
index 6b0d99cae3..faf67710e0 100644
--- a/source4/lib/dcom/common/tables.c
+++ b/source4/lib/dcom/common/tables.c
@@ -76,10 +76,13 @@ const void *dcom_proxy_vtable_by_iid(const struct GUID *iid)
NTSTATUS dcom_register_interface(const void *_iface)
{
const struct dcom_interface *iface = _iface;
- struct interface_list *l = talloc_zero_p(interfaces, struct interface_list);
+ struct interface_list *l;
+
+ l = talloc_zero_p(interfaces?interfaces:talloc_autofree_context(),
+ struct interface_list);
l->interface = *iface;
-
+
DLIST_ADD(interfaces, l);
return NT_STATUS_OK;
@@ -88,7 +91,8 @@ NTSTATUS dcom_register_interface(const void *_iface)
NTSTATUS dcom_register_class(const void *_class)
{
const struct dcom_class *class = _class;
- struct class_list *l = talloc_zero_p(classes, struct class_list);
+ struct class_list *l = talloc_zero_p(classes?classes:talloc_autofree_context(),
+ struct class_list);
l->class = *class;
diff --git a/source4/lib/registry/common/reg_interface.c b/source4/lib/registry/common/reg_interface.c
index 9b03a69f3f..442b34bc13 100644
--- a/source4/lib/registry/common/reg_interface.c
+++ b/source4/lib/registry/common/reg_interface.c
@@ -44,7 +44,7 @@ NTSTATUS registry_register(const void *_hive_ops)
return NT_STATUS_OBJECT_NAME_COLLISION;
}
- entry = talloc_p(NULL, struct reg_init_function_entry);
+ entry = talloc_p(talloc_autofree_context(), struct reg_init_function_entry);
entry->hive_functions = hive_ops;
DLIST_ADD(backends, entry);
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;
+}
diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h
index 6ebba447aa..9e828f2f0d 100644
--- a/source4/lib/talloc/talloc.h
+++ b/source4/lib/talloc/talloc.h
@@ -91,6 +91,7 @@ void *talloc_array(const void *ctx, size_t el_size, unsigned count, const char *
void *talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name);
void *talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name);
void *talloc_realloc_fn(const void *context, void *ptr, size_t size);
+void *talloc_autofree_context(void);
#endif
diff --git a/source4/lib/talloc/talloc_guide.txt b/source4/lib/talloc/talloc_guide.txt
index b3b148d476..ce3c8bde68 100644
--- a/source4/lib/talloc/talloc_guide.txt
+++ b/source4/lib/talloc/talloc_guide.txt
@@ -490,3 +490,9 @@ implementation encapsulates the functionality of malloc(), free() and
realloc() in one call, which is why it is useful to be able to pass
around a single function pointer.
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+void *talloc_autofree_context(void);
+
+This is a handy utility function that returns a talloc context
+which will be automatically freed on program exit. This can be used
+to reduce the noise in memory leak reports.