The TDB2 tests are stricter about this; they want every error logged.
bool found_recovery = false;
tdb1_len_t dead;
bool locked;
bool found_recovery = false;
tdb1_len_t dead;
bool locked;
/* We may have a write lock already, so don't re-lock. */
if (tdb->file->allrecord_lock.count != 0) {
/* We may have a write lock already, so don't re-lock. */
if (tdb->file->allrecord_lock.count != 0) {
}
/* One big malloc: pointers then bit arrays. */
}
/* One big malloc: pointers then bit arrays. */
- hashes = (unsigned char **)calloc(
- 1, sizeof(hashes[0]) * (1+tdb->tdb1.header.hash_size)
- + BITMAP_BITS / CHAR_BIT * (1+tdb->tdb1.header.hash_size));
+ alloc_len = sizeof(hashes[0]) * (1+tdb->tdb1.header.hash_size)
+ + BITMAP_BITS / CHAR_BIT * (1+tdb->tdb1.header.hash_size);
+ hashes = (unsigned char **)calloc(1, alloc_len);
- tdb->last_error = TDB_ERR_OOM;
+ tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
+ "tdb_check: could not allocate %zu",
+ alloc_len);
char *new_map_ptr = (char *)realloc(tdb->file->map_ptr,
tdb->file->map_size);
if (!new_map_ptr) {
char *new_map_ptr = (char *)realloc(tdb->file->map_ptr,
tdb->file->map_size);
if (!new_map_ptr) {
+ tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM,
+ TDB_LOG_ERROR,
+ "tdb1_expand: no memory");
tdb->file->map_size -= size;
goto fail;
}
tdb->file->map_size -= size;
goto fail;
}
struct tdb1_header *newdb;
size_t size;
int hash_size = TDB1_DEFAULT_HASH_SIZE;
struct tdb1_header *newdb;
size_t size;
int hash_size = TDB1_DEFAULT_HASH_SIZE;
- enum TDB_ERROR ret = TDB_ERR_IO;
tdb_context_init(tdb, max_dead);
tdb_context_init(tdb, max_dead);
/* We make it up in memory, then write it out if not internal */
size = sizeof(struct tdb1_header) + (hash_size+1)*sizeof(tdb1_off_t);
if (!(newdb = (struct tdb1_header *)calloc(size, 1))) {
/* We make it up in memory, then write it out if not internal */
size = sizeof(struct tdb1_header) + (hash_size+1)*sizeof(tdb1_off_t);
if (!(newdb = (struct tdb1_header *)calloc(size, 1))) {
+ return tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
+ "Could not allocate new database header");
}
/* Fill in the header */
}
/* Fill in the header */
tdb->file->map_ptr = (char *)newdb;
return TDB_SUCCESS;
}
tdb->file->map_ptr = (char *)newdb;
return TDB_SUCCESS;
}
- if (lseek(tdb->file->fd, 0, SEEK_SET) == -1)
+ if (lseek(tdb->file->fd, 0, SEEK_SET) == -1) {
+ ret = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
+ "tdb1_new_database: lseek failed");
- if (ftruncate(tdb->file->fd, 0) == -1)
+ if (ftruncate(tdb->file->fd, 0) == -1) {
+ ret = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
+ "tdb1_new_database: ftruncate failed");
- /* we still have "ret == TDB_ERR_IO" here */
- if (tdb1_write_all(tdb->file->fd, newdb, size))
- ret = TDB_SUCCESS;
+ if (!tdb1_write_all(tdb->file->fd, newdb, size)) {
+ ret = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
+ "tdb1_new_database: write failed");
+ goto fail;
+ }
+ ret = TDB_SUCCESS;
fails and we are left with a dead spot in the tdb. */
if (!(p = (char *)malloc(key.dsize + dbuf.dsize))) {
fails and we are left with a dead spot in the tdb. */
if (!(p = (char *)malloc(key.dsize + dbuf.dsize))) {
- tdb->last_error = TDB_ERR_OOM;
+ tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
+ "tdb1_store: out of memory"
+ " allocating copy");