]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/check.c
tdb2: log a message on allocation failure in tdb_check()
[ccan] / ccan / tdb2 / check.c
index 5a238a1c48274c507511518bea9d060daaa2e8de..afb682f5e74c8869f77a12ca8436f797b5413ff2 100644 (file)
@@ -512,7 +512,7 @@ size_t dead_space(struct tdb_context *tdb, tdb_off_t off)
 
        for (len = 0; off + len < tdb->map_size; len++) {
                char c;
-               if (tdb->methods->read(tdb, off, &c, 1))
+               if (tdb->methods->tread(tdb, off, &c, 1))
                        return 0;
                if (c != 0 && c != 0x43)
                        break;
@@ -603,8 +603,13 @@ static bool check_linear(struct tdb_context *tdb,
                        }
                        /* This record should be in free lists. */
                        if (frec_ftable(&rec.f) != TDB_FTABLE_NONE
-                           && !append(fr, num_free, off))
+                           && !append(fr, num_free, off)) {
+                               tdb_logerr(tdb, TDB_ERR_OOM,
+                                          TDB_DEBUG_ERROR,
+                                          "tdb_check: tracking %zu'th"
+                                          " free record.", *num_free);
                                return false;
+                       }
                } else if (rec_magic(&rec.u) == TDB_USED_MAGIC
                           || rec_magic(&rec.u) == TDB_CHAIN_MAGIC
                           || rec_magic(&rec.u) == TDB_HTABLE_MAGIC
@@ -612,8 +617,13 @@ static bool check_linear(struct tdb_context *tdb,
                        uint64_t klen, dlen, extra;
 
                        /* This record is used! */
-                       if (!append(used, num_used, off))
+                       if (!append(used, num_used, off)) {
+                               tdb_logerr(tdb, TDB_ERR_OOM,
+                                          TDB_DEBUG_ERROR,
+                                          "tdb_check: tracking %zu'th"
+                                          " used record.", *num_used);
                                return false;
+                       }
 
                        klen = rec_key_length(&rec.u);
                        dlen = rec_data_length(&rec.u);
@@ -700,9 +710,13 @@ int tdb_check(struct tdb_context *tdb,
 
        tdb_allrecord_unlock(tdb, F_RDLCK);
        tdb_unlock_expand(tdb, F_RDLCK);
+       free(fr);
+       free(used);
        return 0;
 
 fail:
+       free(fr);
+       free(used);
        tdb_allrecord_unlock(tdb, F_RDLCK);
        tdb_unlock_expand(tdb, F_RDLCK);
        return -1;