s4-ldb: Use _ldb_msg_add_el() in ldb_msg_add()
authorKamen Mazdrashki <kamenim@samba.org>
Fri, 9 Jul 2010 18:54:21 +0000 (21:54 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Sat, 10 Jul 2010 20:03:14 +0000 (23:03 +0300)
Previous implementation was 'leaking' attribute name
string, that is allocated by ldb_msg_add_empty()

source4/lib/ldb/common/ldb_msg.c

index 75c616572077a1aa6023719e21fe2e4585c45f40..c00fa5a0f1868f28a704592bc4ea8eae400a573e 100644 (file)
@@ -186,15 +186,21 @@ int ldb_msg_add(struct ldb_message *msg,
                const struct ldb_message_element *el, 
                int flags)
 {
+       int ret;
+       struct ldb_message_element *el_new;
        /* We have to copy this, just in case *el is a pointer into
         * what ldb_msg_add_empty() is about to realloc() */
        struct ldb_message_element el_copy = *el;
-       if (ldb_msg_add_empty(msg, el->name, flags, NULL) != LDB_SUCCESS) {
-               return LDB_ERR_OPERATIONS_ERROR;
+
+       ret = _ldb_msg_add_el(msg, &el_new);
+       if (ret != LDB_SUCCESS) {
+               return ret;
        }
 
-       msg->elements[msg->num_elements-1] = el_copy;
-       msg->elements[msg->num_elements-1].flags = flags;
+       el_new->flags      = flags;
+       el_new->name       = el_copy.name;
+       el_new->num_values = el_copy.num_values;
+       el_new->values     = el_copy.values;
 
        return LDB_SUCCESS;
 }