summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-11-05 18:50:29 +1100
committerAndrew Tridgell <tridge@samba.org>2010-11-05 23:42:09 +1100
commiteaabb5950fe89c15b575ffb37b35137d8a848c01 (patch)
tree06f46f91c86316435363c521da144024b8c086a6 /source4/lib/ldb
parent5fcb426d9a0bc4e2076a278babe3f0f2a550d54e (diff)
downloadsamba-eaabb5950fe89c15b575ffb37b35137d8a848c01.tar.gz
samba-eaabb5950fe89c15b575ffb37b35137d8a848c01.tar.bz2
samba-eaabb5950fe89c15b575ffb37b35137d8a848c01.zip
s4-ldb: much more memory efficient msg filtering
this ensures we don't leave unnecessary attributes in returned ldb objects Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index ca47fa3a5d..5df1e4d59e 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -329,6 +329,8 @@ int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs)
{
unsigned int i;
int keep_all = 0;
+ struct ldb_message_element *el2;
+ uint32_t num_elements;
if (attrs) {
/* check for special attrs */
@@ -355,6 +357,12 @@ int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs)
return 0;
}
+ el2 = talloc_array(msg, struct ldb_message_element, msg->num_elements);
+ if (el2 == NULL) {
+ return -1;
+ }
+ num_elements = 0;
+
for (i = 0; i < msg->num_elements; i++) {
unsigned int j;
int found = 0;
@@ -366,12 +374,21 @@ int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs)
}
}
- if (!found) {
- ldb_msg_remove_attr(msg, msg->elements[i].name);
- i--;
+ if (found) {
+ el2[num_elements] = msg->elements[i];
+ talloc_steal(el2, el2[num_elements].name);
+ talloc_steal(el2, el2[num_elements].values);
+ num_elements++;
}
}
+ talloc_free(msg->elements);
+ msg->elements = talloc_realloc(msg, el2, struct ldb_message_element, msg->num_elements);
+ if (msg->elements == NULL) {
+ return -1;
+ }
+ msg->num_elements = num_elements;
+
return 0;
}