From: Volker Lendecke Date: Mon, 12 Apr 2021 08:37:11 +0000 (+0000) Subject: lib: Simplify tdb_fetch_int32() X-Git-Tag: tevent-0.11.0~1109 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=604c16453c7cee96e23cec52cbc061a15e78b703;p=thirdparty%2Fsamba.git lib: Simplify tdb_fetch_int32() With tdb_parse_record we don't need malloc/SAFE_FREE. The semantics are a bit different from tdb_parse_uint32: We just return -1 on error, but this could be overloaded with a valid -1 record value. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/lib/util/util_tdb.c b/lib/util/util_tdb.c index 66caaa5af60..70eeceff391 100644 --- a/lib/util/util_tdb.c +++ b/lib/util/util_tdb.c @@ -132,20 +132,19 @@ void tdb_read_unlock_bystring(struct tdb_context *tdb, const char *keyval) Output is int32_t in native byte order. ****************************************************************************/ -static int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, TDB_DATA key) +static int fetch_int32_parser(TDB_DATA key, TDB_DATA data, void *private_data) { - TDB_DATA data; - int32_t ret; - - data = tdb_fetch(tdb, key); - if (!data.dptr || data.dsize != sizeof(int32_t)) { - SAFE_FREE(data.dptr); - return -1; + if (data.dsize == sizeof(int32_t)) { + *((int32_t *)private_data) = PULL_LE_I32(data.dptr, 0); } + return 0; +} - ret = IVAL(data.dptr,0); - SAFE_FREE(data.dptr); - return ret; +static int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, TDB_DATA key) +{ + int v = -1; + tdb_parse_record(tdb, key, fetch_int32_parser, &v); + return v; } /****************************************************************************