X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fcheck.c;h=df61184f60822fd0dac8af95a16897f28fb3a772;hp=d614d4cbf7778a9ebc5927c09ca71dc7736f3574;hb=71c1a95f1a9d2e33f3e37b287f9f8118ee01bf7f;hpb=2491b65a6d10cd6ca1a3e05bf535eb0180047922 diff --git a/ccan/tdb2/check.c b/ccan/tdb2/check.c index d614d4cb..df61184f 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,7 +603,7 @@ 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)) return false; } else if (rec_magic(&rec.u) == TDB_USED_MAGIC || rec_magic(&rec.u) == TDB_CHAIN_MAGIC @@ -661,7 +661,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 +676,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 +700,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;