From baa8ed20153883ba2c5cfb5211cd1255b38b6a20 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 26 Nov 2006 03:59:01 +0000 Subject: r19905: use ldb_dn_new_fmt() to avoid double strdups (This used to be commit 32a6b6c75b041bf829ecf272a9b10164f7ffe12b) --- source4/lib/ldb/ldb_tdb/ldb_index.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'source4/lib/ldb') diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 872afb78ae..045be985a4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -107,7 +107,6 @@ static struct ldb_dn *ltdb_index_key(struct ldb_context *ldb, const char *attr, const struct ldb_val *value) { struct ldb_dn *ret; - char *dn; struct ldb_val v; const struct ldb_attrib_handler *h; char *attr_folded; @@ -128,27 +127,17 @@ static struct ldb_dn *ltdb_index_key(struct ldb_context *ldb, if (ldb_should_b64_encode(&v)) { char *vstr = ldb_base64_encode(ldb, (char *)v.data, v.length); if (!vstr) return NULL; - dn = talloc_asprintf(ldb, "%s:%s::%s", LTDB_INDEX, attr_folded, vstr); + ret = ldb_dn_new_fmt(ldb, ldb, "%s:%s::%s", LTDB_INDEX, attr_folded, vstr); talloc_free(vstr); - if (v.data != value->data) { - talloc_free(v.data); - } - talloc_free(attr_folded); - if (dn == NULL) return NULL; - goto done; + } else { + ret = ldb_dn_new_fmt(ldb, ldb, "%s:%s:%.*s", LTDB_INDEX, attr_folded, (int)v.length, (char *)v.data); } - dn = talloc_asprintf(ldb, "%s:%s:%.*s", - LTDB_INDEX, attr_folded, (int)v.length, (char *)v.data); - if (v.data != value->data) { talloc_free(v.data); } talloc_free(attr_folded); -done: - ret = ldb_dn_new(ldb, ldb, dn); - talloc_free(dn); return ret; } -- cgit