svn commit: samba r19305 - in branches/SAMBA_4_0/source/lib/ldb/common: .

idra at samba.org idra at samba.org
Mon Oct 16 01:01:38 GMT 2006


Author: idra
Date: 2006-10-16 01:01:37 +0000 (Mon, 16 Oct 2006)
New Revision: 19305

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

Log:

Potential memleak on the ldb_context if we don't use a temp mem context


Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c	2006-10-16 01:00:47 UTC (rev 19304)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c	2006-10-16 01:01:37 UTC (rev 19305)
@@ -232,6 +232,8 @@
 	return total;
 }
 
+#undef CHECK_RET
+
 /*
   encode as base64 to a file
 */
@@ -264,6 +266,9 @@
 	{NULL, 0}
 };
 
+/* this macro is used to handle the return checking on fprintf_fn() */
+#define CHECK_RET do { if (ret < 0) { talloc_free(mem_ctx); return ret; } total += ret; } while (0)
+
 /*
   write to ldif, using a caller supplied write method
 */
@@ -272,10 +277,13 @@
 		   void *private_data,
 		   const struct ldb_ldif *ldif)
 {
+	TALLOC_CTX *mem_ctx;
 	unsigned int i, j;
 	int total=0, ret;
 	const struct ldb_message *msg;
 
+	mem_ctx = talloc_named_const(NULL, 0, "ldb_ldif_write");
+
 	msg = ldif->msg;
 
 	ret = fprintf_fn(private_data, "dn: %s\n", ldb_dn_linearize(msg->dn, msg->dn));
@@ -290,6 +298,7 @@
 		if (!ldb_changetypes[i].name) {
 			ldb_debug(ldb, LDB_DEBUG_ERROR, "Error: Invalid ldif changetype %d\n",
 				  ldif->changetype);
+			talloc_free(mem_ctx);
 			return -1;
 		}
 		ret = fprintf_fn(private_data, "changetype: %s\n", ldb_changetypes[i].name);
@@ -320,7 +329,7 @@
 
 		for (j=0;j<msg->elements[i].num_values;j++) {
 			struct ldb_val v;
-			ret = h->ldif_write_fn(ldb, ldb, &msg->elements[i].values[j], &v);
+			ret = h->ldif_write_fn(ldb, mem_ctx, &msg->elements[i].values[j], &v);
 			CHECK_RET;
 			if (ldb_should_b64_encode(&v)) {
 				ret = fprintf_fn(private_data, "%s:: ", 



More information about the samba-cvs mailing list