From 299fc7522858e2d7ee6c54310a4e157c8142c74f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 9 Aug 2012 19:58:31 +1000 Subject: [PATCH] lib/ldb: Use tdb_exists() rather than tdb_fetch()/talloc_free() This avoids pulling the record and doing an allocation when we just want to know if it exists. Andrew Bartlett --- lib/ldb/ldb_tdb/ldb_search.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_search.c b/lib/ldb/ldb_tdb/ldb_search.c index 5e2050065cb..e631f7bacae 100644 --- a/lib/ldb/ldb_tdb/ldb_search.c +++ b/lib/ldb/ldb_tdb/ldb_search.c @@ -212,7 +212,8 @@ static int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); - TDB_DATA tdb_key, tdb_data; + TDB_DATA tdb_key; + int exists; if (ldb_dn_is_null(dn)) { return LDB_ERR_NO_SUCH_OBJECT; @@ -224,14 +225,13 @@ static int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn) return LDB_ERR_OPERATIONS_ERROR; } - tdb_data = tdb_fetch(ltdb->tdb, tdb_key); + exists = tdb_exists(ltdb->tdb, tdb_key); talloc_free(tdb_key.dptr); - if (!tdb_data.dptr) { - return LDB_ERR_NO_SUCH_OBJECT; + + if (exists) { + return LDB_SUCCESS; } - - free(tdb_data.dptr); - return LDB_SUCCESS; + return LDB_ERR_NO_SUCH_OBJECT; } /* -- 2.11.4.GIT