s4-openldap: Remove use of talloc_reference in ldb_map_outbound.c
authorNadezhda Ivanova <nivanova@symas.com>
Wed, 18 Sep 2013 22:31:24 +0000 (15:31 -0700)
committerNadezhda Ivanova <nivanova@symas.com>
Tue, 24 Sep 2013 01:40:25 +0000 (18:40 -0700)
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 <nivanova@symas.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/ldb/ldb_map/ldb_map_outbound.c

index b6357bdca332c0f6db0bf733bb018548828e180e..1ee2dfe12de912f6fd64ceefad0429b65b23ac99 100644 (file)
@@ -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;j<el->num_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;