svn commit: samba r19365 - in branches/SAMBA_4_0/source/lib/ldb: common include ldb_tdb

tridge at samba.org tridge at samba.org
Tue Oct 17 05:50:03 GMT 2006


Author: tridge
Date: 2006-10-17 05:50:01 +0000 (Tue, 17 Oct 2006)
New Revision: 19365

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

Log:

fixed a memory leak in the ldb attribute handling

Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c
   branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c	2006-10-17 01:40:29 UTC (rev 19364)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c	2006-10-17 05:50:01 UTC (rev 19365)
@@ -39,6 +39,7 @@
 			    const struct ldb_attrib_handler *handlers, 
 			    unsigned num_handlers)
 {
+	int i;
 	struct ldb_attrib_handler *h;
 	h = talloc_realloc(ldb, ldb->schema.attrib_handlers,
 			   struct ldb_attrib_handler,
@@ -50,6 +51,16 @@
 	ldb->schema.attrib_handlers = h;
 	memcpy(h + ldb->schema.num_attrib_handlers, 
 	       handlers, sizeof(*h) * num_handlers);
+	for (i=0;i<num_handlers;i++) {
+		if (h[ldb->schema.num_attrib_handlers+i].flags & LDB_ATTR_FLAG_ALLOCATED) {
+			h[ldb->schema.num_attrib_handlers+i].attr = talloc_strdup(ldb->schema.attrib_handlers,
+										  h[ldb->schema.num_attrib_handlers+i].attr);
+			if (h[ldb->schema.num_attrib_handlers+i].attr == NULL) {
+				ldb_oom(ldb);
+				return -1;
+			}
+		}
+	}
 	ldb->schema.num_attrib_handlers += num_handlers;
 	return 0;
 }
@@ -129,6 +140,9 @@
 	if (h == &ldb_default_attrib_handler) {
 		return;
 	}
+	if (h->flags & LDB_ATTR_FLAG_ALLOCATED) {
+		talloc_free(h->attr);
+	}
 	i = h - ldb->schema.attrib_handlers;
 	if (i < ldb->schema.num_attrib_handlers - 1) {
 		memmove(&ldb->schema.attrib_handlers[i], 

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2006-10-17 01:40:29 UTC (rev 19364)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2006-10-17 05:50:01 UTC (rev 19365)
@@ -357,6 +357,9 @@
 */
 #define LDB_ATTR_FLAG_HIDDEN       (1<<0) 
 
+/* the attribute handler name should be freed when released */
+#define LDB_ATTR_FLAG_ALLOCATED    (1<<1) 
+
 /**
    The attribute is constructed from other attributes
 */

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c	2006-10-17 01:40:29 UTC (rev 19364)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c	2006-10-17 05:50:01 UTC (rev 19365)
@@ -71,13 +71,7 @@
 
 	msg = ltdb->cache->attributes;
 	for (i=0;i<msg->num_elements;i++) {
-		const struct ldb_attrib_handler *h;
-		/* this is rather ugly - a consequence of const handling */
-		h = ldb_attrib_handler(module->ldb, msg->elements[i].name);
 		ldb_remove_attrib_handler(module->ldb, msg->elements[i].name);
-		if (strcmp(h->attr, msg->elements[i].name) == 0) {
-			talloc_steal(msg, h->attr);
-		}
 	}
 
 	talloc_free(ltdb->cache->attributes);
@@ -163,11 +157,11 @@
 			goto failed;
 		}
 		h2 = *h;
-		h2.attr = talloc_strdup(module, msg->elements[i].name);
+		h2.attr = msg->elements[i].name;
+		h2.flags |= LDB_ATTR_FLAG_ALLOCATED;
 		if (ldb_set_attrib_handlers(module->ldb, &h2, 1) != 0) {
 			goto failed;
 		}
-		talloc_steal(module->ldb->schema.attrib_handlers, h2.attr);
 	}
 
 	return 0;



More information about the samba-cvs mailing list