X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fcheck.c;h=afb682f5e74c8869f77a12ca8436f797b5413ff2;hp=d614d4cbf7778a9ebc5927c09ca71dc7736f3574;hb=1e8fde07b5d6fa50731d914542d72465047521fe;hpb=2491b65a6d10cd6ca1a3e05bf535eb0180047922 diff --git a/ccan/tdb2/check.c b/ccan/tdb2/check.c index d614d4cb..afb682f5 100644 --- a/ccan/tdb2/check.c +++ b/ccan/tdb2/check.c @@ -453,7 +453,7 @@ static bool check_free(struct tdb_context *tdb, static bool check_free_table(struct tdb_context *tdb, tdb_off_t ftable_off, unsigned ftable_num, - tdb_off_t free[], + tdb_off_t fr[], size_t num_free, size_t *num_found) { @@ -487,7 +487,7 @@ static bool check_free_table(struct tdb_context *tdb, return false; /* FIXME: Check hash bits */ - p = asearch(&off, free, num_free, off_cmp); + p = asearch(&off, fr, num_free, off_cmp); if (!p) { tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR, @@ -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; @@ -522,7 +522,7 @@ size_t dead_space(struct tdb_context *tdb, tdb_off_t off) static bool check_linear(struct tdb_context *tdb, tdb_off_t **used, size_t *num_used, - tdb_off_t **free, size_t *num_free, + tdb_off_t **fr, size_t *num_free, tdb_off_t recovery) { tdb_off_t off; @@ -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(free, 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); @@ -661,7 +671,7 @@ int tdb_check(struct tdb_context *tdb, int (*check)(TDB_DATA key, TDB_DATA data, void *private_data), void *private_data) { - tdb_off_t *free = NULL, *used = NULL, ft, recovery; + tdb_off_t *fr = NULL, *used = NULL, ft, recovery; size_t num_free = 0, num_used = 0, num_found = 0, num_ftables = 0; if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false) != 0) @@ -676,13 +686,13 @@ int tdb_check(struct tdb_context *tdb, goto fail; /* First we do a linear scan, checking all records. */ - if (!check_linear(tdb, &used, &num_used, &free, &num_free, recovery)) + if (!check_linear(tdb, &used, &num_used, &fr, &num_free, recovery)) goto fail; for (ft = first_ftable(tdb); ft; ft = next_ftable(tdb, ft)) { if (ft == TDB_OFF_ERR) goto fail; - if (!check_free_table(tdb, ft, num_ftables, free, num_free, + if (!check_free_table(tdb, ft, num_ftables, fr, num_free, &num_found)) goto fail; num_ftables++; @@ -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;