]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Simplify tdb_fetch_uint32_t()
authorVolker Lendecke <vl@samba.org>
Mon, 12 Apr 2021 08:29:02 +0000 (08:29 +0000)
committerJeremy Allison <jra@samba.org>
Mon, 19 Apr 2021 18:18:31 +0000 (18:18 +0000)
With tdb_parse_record() we don't need malloc/SAFE_FREE

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/util_tdb.c

index ee3e8ec0fa40c2b0d17e620a07cfc2ff14d8a6fe..66caaa5af609d77d2981483271a8a132df547dc1 100644 (file)
@@ -191,20 +191,20 @@ int tdb_store_int32(struct tdb_context *tdb, const char *keystr, int32_t v)
  Output is uint32_t in native byte order.
 ****************************************************************************/
 
-static bool tdb_fetch_uint32_byblob(struct tdb_context *tdb, TDB_DATA key,
-                                   uint32_t *value)
+static int fetch_uint32_parser(TDB_DATA key, TDB_DATA data, void *private_data)
 {
-       TDB_DATA data;
-
-       data = tdb_fetch(tdb, key);
-       if (!data.dptr || data.dsize != sizeof(uint32_t)) {
-               SAFE_FREE(data.dptr);
-               return false;
+       if (data.dsize != sizeof(uint32_t)) {
+               return -1;
        }
+       *((uint32_t *)private_data) = PULL_LE_U32(data.dptr, 0);
+       return 0;
+}
 
-       *value = IVAL(data.dptr,0);
-       SAFE_FREE(data.dptr);
-       return true;
+static bool tdb_fetch_uint32_byblob(struct tdb_context *tdb, TDB_DATA key,
+                                   uint32_t *value)
+{
+       int ret = tdb_parse_record(tdb, key, fetch_uint32_parser, value);
+       return ret;
 }
 
 /****************************************************************************