ldb: Prepare for adding flags to ltdb_search_dn1() to control memory allocation
authorAndrew Bartlett <abartlet@samba.org>
Tue, 26 Jul 2016 12:20:27 +0000 (00:20 +1200)
committerStefan Metzmacher <metze@samba.org>
Thu, 28 Jul 2016 08:06:12 +0000 (10:06 +0200)
Because the memory layout will change in the next commit, we need to add
a talloc_steal() of msg, which holds the memory on one big chunk.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_index.c

index ede37f99d3dfb4b1d6f4b4deddf83bf943195f5c..e6bfb1b623988607383c72c8911a8e8bffcc24f0 100644 (file)
@@ -192,10 +192,18 @@ normal_index:
                return LDB_SUCCESS;
        }
 
-       /* we avoid copying the strings by stealing the list */
+       /*
+        * we avoid copying the strings by stealing the list.  We have
+        * to steal msg onto el->values (which looks odd) because we
+        * asked for the memory to be allocated on msg, not on each
+        * value with LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC above
+        */
+       talloc_steal(el->values, msg);
        list->dn = talloc_steal(list, el->values);
        list->count = el->num_values;
 
+       /* We don't need msg->elements any more */
+       talloc_free(msg->elements);
        return LDB_SUCCESS;
 }