summaryrefslogtreecommitdiff
path: root/source3/lib/ldb/common/ldb_ldif.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-10-21 00:10:19 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:15:35 -0500
commit7a390a0dabcdadb30196662b6cdec512bf81dcb4 (patch)
tree8ed126e072e4446ad47d25f277059af5ccd556cc /source3/lib/ldb/common/ldb_ldif.c
parentaa3ca346d82da2501406cc1f482643b20905e467 (diff)
downloadsamba-7a390a0dabcdadb30196662b6cdec512bf81dcb4.tar.gz
samba-7a390a0dabcdadb30196662b6cdec512bf81dcb4.tar.bz2
samba-7a390a0dabcdadb30196662b6cdec512bf81dcb4.zip
r19430: merge recent ldb changes from Samba4. This includes memory leak fixes
and significant speedups (This used to be commit bb5c205fef90aa8b89ba400fb9f2f37a111676a8)
Diffstat (limited to 'source3/lib/ldb/common/ldb_ldif.c')
-rw-r--r--source3/lib/ldb/common/ldb_ldif.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/source3/lib/ldb/common/ldb_ldif.c b/source3/lib/ldb/common/ldb_ldif.c
index 0c31f25cc7..4992eb01ad 100644
--- a/source3/lib/ldb/common/ldb_ldif.c
+++ b/source3/lib/ldb/common/ldb_ldif.c
@@ -232,6 +232,8 @@ static int fold_string(int (*fprintf_fn)(void *, const char *, ...), void *priva
return total;
}
+#undef CHECK_RET
+
/*
encode as base64 to a file
*/
@@ -264,6 +266,9 @@ static const struct {
{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 @@ int ldb_ldif_write(struct ldb_context *ldb,
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 @@ int ldb_ldif_write(struct ldb_context *ldb,
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 @@ int ldb_ldif_write(struct ldb_context *ldb,
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:: ",
@@ -541,6 +550,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
if (!chunk) {
goto failed;
}
+ talloc_steal(ldif, chunk);
msg->private_data = chunk;
s = chunk;