From: Andrew Bartlett Date: Wed, 2 Aug 2023 02:12:07 +0000 (+1200) Subject: dsdb: Replace talloc_steal() with a shallow copy and reference in dsdb_paged_results X-Git-Tag: tevent-0.16.0~1294 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b51091c20a3c807932bcc986ebb8a676e0ffe6a;p=thirdparty%2Fsamba.git dsdb: Replace talloc_steal() with a shallow copy and reference in dsdb_paged_results We should not be stealing caller memory like this, and while a talloc_reference() is not much better, this combined with a shallow copy should be a little better in terms of polite memory management. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15442 Signed-off-by: Andrew Bartlett Reviewed-by: Stefan Metzmacher --- diff --git a/source4/dsdb/samdb/ldb_modules/paged_results.c b/source4/dsdb/samdb/ldb_modules/paged_results.c index a6f2bf22098..83729b02c0b 100644 --- a/source4/dsdb/samdb/ldb_modules/paged_results.c +++ b/source4/dsdb/samdb/ldb_modules/paged_results.c @@ -681,6 +681,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) struct ldb_control *ext_ctrl; struct ldb_control **controls; static const char * const attrs[1] = { NULL }; + void *ref = NULL; if (paged_ctrl->size == 0) { return LDB_ERR_OPERATIONS_ERROR; @@ -739,7 +740,25 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) return ret; } - ac->store->expr = talloc_steal(ac->store, req->op.search.tree); + /* + * LDB does not have a function to take a full copy of + * this, but at least take a shallow copy + */ + ac->store->expr = ldb_parse_tree_copy_shallow(ac->store, + req->op.search.tree); + + if (ac->store->expr == NULL) { + return ldb_operr(ldb); + } + + /* + * As the above is only a shallow copy, take a + * reference to ensure the values are kept around + */ + ref = talloc_reference(ac->store, req->op.search.tree); + if (ref == NULL) { + return ldb_module_oom(module); + } ac->store->expr_str = ldb_filter_from_tree(ac->store, req->op.search.tree); if (ac->store->expr_str == NULL) {