svn commit: samba r4479 - in branches/SAMBA_4_0/source: lib/dcom/common lib/registry/common lib/talloc librpc/rpc

tridge at samba.org tridge at samba.org
Sun Jan 2 12:55:33 GMT 2005


Author: tridge
Date: 2005-01-02 12:55:33 +0000 (Sun, 02 Jan 2005)
New Revision: 4479

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=4479

Log:
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



Modified:
   branches/SAMBA_4_0/source/lib/dcom/common/tables.c
   branches/SAMBA_4_0/source/lib/registry/common/reg_interface.c
   branches/SAMBA_4_0/source/lib/talloc/talloc.c
   branches/SAMBA_4_0/source/lib/talloc/talloc.h
   branches/SAMBA_4_0/source/lib/talloc/talloc_guide.txt
   branches/SAMBA_4_0/source/librpc/rpc/dcerpc.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/dcom/common/tables.c
===================================================================
--- branches/SAMBA_4_0/source/lib/dcom/common/tables.c	2005-01-02 09:48:17 UTC (rev 4478)
+++ branches/SAMBA_4_0/source/lib/dcom/common/tables.c	2005-01-02 12:55:33 UTC (rev 4479)
@@ -76,10 +76,13 @@
 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_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;
 	

Modified: branches/SAMBA_4_0/source/lib/registry/common/reg_interface.c
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/common/reg_interface.c	2005-01-02 09:48:17 UTC (rev 4478)
+++ branches/SAMBA_4_0/source/lib/registry/common/reg_interface.c	2005-01-02 12:55:33 UTC (rev 4479)
@@ -44,7 +44,7 @@
 		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);

Modified: branches/SAMBA_4_0/source/lib/talloc/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc.c	2005-01-02 09:48:17 UTC (rev 4478)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc.c	2005-01-02 12:55:33 UTC (rev 4479)
@@ -67,6 +67,7 @@
    NULL
 */
 static const void *null_context;
+static void *cleanup_context;
 
 
 struct talloc_reference_handle {
@@ -1004,3 +1005,23 @@
 {
 	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;
+}

Modified: branches/SAMBA_4_0/source/lib/talloc/talloc.h
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc.h	2005-01-02 09:48:17 UTC (rev 4478)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc.h	2005-01-02 12:55:33 UTC (rev 4479)
@@ -91,6 +91,7 @@
 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
 

Modified: branches/SAMBA_4_0/source/lib/talloc/talloc_guide.txt
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc_guide.txt	2005-01-02 09:48:17 UTC (rev 4478)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc_guide.txt	2005-01-02 12:55:33 UTC (rev 4479)
@@ -490,3 +490,9 @@
 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.

Modified: branches/SAMBA_4_0/source/librpc/rpc/dcerpc.c
===================================================================
--- branches/SAMBA_4_0/source/librpc/rpc/dcerpc.c	2005-01-02 09:48:17 UTC (rev 4478)
+++ branches/SAMBA_4_0/source/librpc/rpc/dcerpc.c	2005-01-02 12:55:33 UTC (rev 4479)
@@ -27,21 +27,22 @@
 
 struct dcerpc_interface_list *dcerpc_pipes = NULL;
 
-NTSTATUS librpc_register_interface (const struct dcerpc_interface_table *interface)
+NTSTATUS librpc_register_interface(const struct dcerpc_interface_table *interface)
 {
-	struct dcerpc_interface_list *l = talloc_p(NULL, struct dcerpc_interface_list);
+	struct dcerpc_interface_list *l = talloc_p(talloc_autofree_context(),
+						   struct dcerpc_interface_list);
 		
 	if (idl_iface_by_name (interface->name) != NULL) {
 		DEBUG(0, ("Attempt to register interface %s twice\n", interface->name));
 		return NT_STATUS_OBJECT_NAME_COLLISION;
 	}
 	l->table = interface;
-	
+
 	DLIST_ADD(dcerpc_pipes, l);
 	
   	return NT_STATUS_OK;
 }
-  
+
 /* initialise a dcerpc pipe. */
 struct dcerpc_pipe *dcerpc_pipe_init(void)
 {



More information about the samba-cvs mailing list