]> git.ozlabs.org Git - ccan/commitdiff
tdb2: fix valgrind warnings.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 30 Aug 2010 13:14:54 +0000 (22:44 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 30 Aug 2010 13:14:54 +0000 (22:44 +0930)
The unreserved headers were a real bug; the others could cause a false error too.

ccan/tdb2/lock.c
ccan/tdb2/tdb.c

index 14a7b5e5c65904749bd78647bb7558b12489fb15..c7c449abc1a37091824563475b7aa7558f89e759 100644 (file)
@@ -255,13 +255,18 @@ static int tdb_nest_lock(struct tdb_context *tdb, tdb_off_t offset, int ltype,
 {
        struct tdb_lock_type *new_lck;
 
-       if (offset >= TDB_HASH_LOCK_START + (1ULL << tdb->header.v.hash_bits)
-           + (tdb->header.v.num_zones * (tdb->header.v.free_buckets+1))) {
-               tdb->ecode = TDB_ERR_LOCK;
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                        "tdb_lock: invalid offset %llu for ltype=%d\n",
-                        (long long)offset, ltype);
-               return -1;
+       /* Header is not valid for open lock; valgrind complains. */
+       if (offset >= TDB_HASH_LOCK_START) {
+               if (offset > TDB_HASH_LOCK_START
+                   + (1ULL << tdb->header.v.hash_bits)
+                   + (tdb->header.v.num_zones
+                      * (tdb->header.v.free_buckets+1))) {
+                       tdb->ecode = TDB_ERR_LOCK;
+                       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+                                "tdb_lock: invalid offset %llu ltype=%d\n",
+                                (long long)offset, ltype);
+                       return -1;
+               }
        }
        if (tdb->flags & TDB_NOLOCK)
                return 0;
index 175827e248b8631263d1bba0ac107f670783af41..7544d7a1e13ef1bcea9d13ece2a4a8e01be7a3f0 100644 (file)
@@ -147,7 +147,7 @@ static int tdb_new_database(struct tdb_context *tdb)
                                         sizeof(newdb.hdr.hash_test),
                                         newdb.hdr.hash_seed,
                                         tdb->hash_priv);
-
+       memset(newdb.hdr.reserved, 0, sizeof(newdb.hdr.reserved));
        newdb.hdr.v.generation = 0;
 
        /* The initial zone must cover the initial database size! */