[block-cache] fix leaking validators

The memory for the blocks is explicitly managed, and the destructors
for the blocks wasn't being called.
This commit is contained in:
Joe Thornber 2014-08-21 12:54:39 +01:00
parent 0d3942cae8
commit 4799becb01
2 changed files with 17 additions and 5 deletions

View File

@ -77,6 +77,21 @@ block_cache::init_free_list(unsigned count)
return 0;
}
void
block_cache::exit_free_list()
{
if (blocks_data_)
free(blocks_data_);
if (blocks_memory_) {
struct block *blocks = static_cast<block *>(blocks_memory_);
for (unsigned i = 0; i < nr_cache_blocks_; i++)
(blocks + i)->~block();
free(blocks_memory_);
}
}
block_cache::block *
block_cache::__alloc_block()
{
@ -475,11 +490,7 @@ block_cache::~block_cache()
flush();
wait_all();
if (blocks_memory_)
free(blocks_memory_);
if (blocks_data_)
free(blocks_data_);
exit_free_list();
if (aio_context_)
io_destroy(aio_context_);

View File

@ -138,6 +138,7 @@ namespace bcache {
private:
int init_free_list(unsigned count);
void exit_free_list();
block *__alloc_block();
void complete_io(block &b, int result);
void issue_low_level(block &b, enum io_iocb_cmd opcode, const char *desc);