svn commit: samba r19360 - in branches/SAMBA_4_0/source/lib: .

tridge at samba.org tridge at samba.org
Tue Oct 17 01:18:33 GMT 2006


Author: tridge
Date: 2006-10-17 01:18:32 +0000 (Tue, 17 Oct 2006)
New Revision: 19360

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

Log:

improve the ldb leak detector - it now takes into account the number
of blocks used at connect time (which depends on how many modules are
loaded)

Modified:
   branches/SAMBA_4_0/source/lib/db_wrap.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/db_wrap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/db_wrap.c	2006-10-17 01:14:01 UTC (rev 19359)
+++ branches/SAMBA_4_0/source/lib/db_wrap.c	2006-10-17 01:18:32 UTC (rev 19360)
@@ -65,13 +65,16 @@
 	return strupper_talloc(mem_ctx, s);
 }
 
-/* check for leaks */
+/* check for memory leaks on the ldb context */
 static int ldb_wrap_destructor(struct ldb_context *ldb)
 {
-	if (talloc_total_blocks(ldb) > 656) {
-		DEBUG(0,("WARNING: probable memory leak in ldb %s - %lu blocks %lu bytes\n",
+	size_t *startup_blocks = (size_t *)ldb_get_opaque(ldb, "startup_blocks");
+	if (startup_blocks &&
+	    talloc_total_blocks(ldb) > *startup_blocks + 100) {
+		DEBUG(0,("WARNING: probable memory leak in ldb %s - %lu blocks (startup %lu) %lu bytes\n",
 			 (char *)ldb_get_opaque(ldb, "wrap_url"), 
 			 (unsigned long)talloc_total_blocks(ldb), 
+			 (unsigned long)*startup_blocks,
 			 (unsigned long)talloc_total_size(ldb)));
 #if 0
 		talloc_report_full(ldb, stdout);
@@ -97,6 +100,7 @@
 	int ret;
 	struct event_context *ev;
 	char *real_url = NULL;
+	size_t *startup_blocks;
 
 	ldb = ldb_init(mem_ctx);
 	if (ldb == NULL) {
@@ -155,7 +159,12 @@
 
 	ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
 
+	/* setup for leak detection */
 	ldb_set_opaque(ldb, "wrap_url", real_url);
+	startup_blocks = talloc(ldb, size_t);
+	*startup_blocks = talloc_total_blocks(ldb);
+	ldb_set_opaque(ldb, "startup_blocks", startup_blocks);
+	
 	talloc_set_destructor(ldb, ldb_wrap_destructor);
 
 	return ldb;



More information about the samba-cvs mailing list