From 75705776929d87f1a694582261c07d1724574370 Mon Sep 17 00:00:00 2001 From: Nadezhda Ivanova Date: Wed, 18 Sep 2013 15:31:24 -0700 Subject: s4-openldap: Remove use of talloc_reference in ldb_map_outbound.c Instead of referencing the values array of the element to the new element, copy them, to avoid use of talloc_reference and remove a warning of talloc_steal with reference. The issue is only relevant when openldap backend is used. Signed-off-by: Nadezhda Ivanova Reviewed-by: Andrew Bartlett Reviewed-by: Jeremy Allison --- lib/ldb/ldb_map/ldb_map_outbound.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/ldb/ldb_map/ldb_map_outbound.c b/lib/ldb/ldb_map/ldb_map_outbound.c index b6357bdca3..1ee2dfe12d 100644 --- a/lib/ldb/ldb_map/ldb_map_outbound.c +++ b/lib/ldb/ldb_map/ldb_map_outbound.c @@ -190,7 +190,7 @@ static int map_attrs_partition(struct ldb_module *module, void *mem_ctx, const c static int ldb_msg_replace(struct ldb_message *msg, const struct ldb_message_element *el) { struct ldb_message_element *old; - + int j; old = ldb_msg_find_element(msg, el->name); /* no local result, add as new element */ @@ -198,18 +198,22 @@ static int ldb_msg_replace(struct ldb_message *msg, const struct ldb_message_ele if (ldb_msg_add_empty(msg, el->name, 0, &old) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - talloc_free(discard_const_p(char, old->name)); + } + else { + talloc_free(old->values); } - /* copy new element */ - *old = *el; - - /* and make sure we reference the contents */ - if (!talloc_reference(msg->elements, el->name)) { + old->values = talloc_array(msg->elements, struct ldb_val, el->num_values); + old->num_values = el->num_values; + if (old->values == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - if (!talloc_reference(msg->elements, el->values)) { - return LDB_ERR_OPERATIONS_ERROR; + /* copy the values into the element */ + for (j=0;jnum_values;j++) { + old->values[j] = ldb_val_dup(old->values, &el->values[j]); + if (old->values[j].data == NULL && el->values[j].length != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } } return 0; -- cgit