lib: Use tdb_parse_record in gencache_set
authorVolker Lendecke <vl@samba.org>
Tue, 25 Nov 2014 21:03:18 +0000 (21:03 +0000)
committerKarolin Seeger <kseeger@samba.org>
Sat, 24 Jan 2015 21:16:09 +0000 (22:16 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Wed Nov 26 14:50:38 CET 2014 on sn-devel-104
(cherry picked from commit ec0c9ad0994d35e22ecc50e552d14582c51622b1)

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11032

source3/lib/gencache.c

index 3e67d9ebe75d2b4fb1e202b2f0f8f542597505d8..2e9c496e37d0f7eec0ca5f8738f2e1afc0277441 100644 (file)
@@ -240,6 +240,17 @@ static bool gencache_have_val(const char *keystr, const DATA_BLOB *data,
        return state.gotit;
 }
 
+static int last_stabilize_parser(TDB_DATA key, TDB_DATA data,
+                                void *private_data)
+{
+       time_t *last_stabilize = private_data;
+
+       if ((data.dsize != 0) && (data.dptr[data.dsize-1] == '\0')) {
+               *last_stabilize = atoi((char *)data.dptr);
+       }
+       return 0;
+}
+
 /**
  * Set an entry in the cache file. If there's no such
  * one, then add it.
@@ -256,7 +267,6 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
                            time_t timeout)
 {
        int ret;
-       TDB_DATA databuf;
        char* val;
        time_t last_stabilize;
        static int writecount;
@@ -326,12 +336,10 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
         */
 
        last_stabilize = 0;
-       databuf = tdb_fetch_compat(cache_notrans, last_stabilize_key());
-       if ((databuf.dptr != NULL)
-           && (databuf.dptr[databuf.dsize-1] == '\0')) {
-               last_stabilize = atoi((char *)databuf.dptr);
-               SAFE_FREE(databuf.dptr);
-       }
+
+       tdb_parse_record(cache_notrans, last_stabilize_key(),
+                        last_stabilize_parser, &last_stabilize);
+
        if ((last_stabilize
             + lp_parm_int(-1, "gencache", "stabilize_interval", 300))
            < time(NULL)) {