lib/ldb: Use tdb_exists() rather than tdb_fetch()/talloc_free()
authorAndrew Bartlett <abartlet@samba.org>
Thu, 9 Aug 2012 09:58:31 +0000 (19:58 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 9 Aug 2012 10:14:22 +0000 (20:14 +1000)
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

index 5e2050065cb9995702e40c14612e7e72a32062dc..e631f7bacaee45432498eebaff1891d0f392ec04 100644 (file)
@@ -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;
 }
 
 /*