From 4799becb0122a4292a89d11f58b69541a274bad0 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 21 Aug 2014 12:54:39 +0100 Subject: [PATCH] [block-cache] fix leaking validators The memory for the blocks is explicitly managed, and the destructors for the blocks wasn't being called. --- block-cache/block_cache.cc | 21 ++++++++++++++++----- block-cache/block_cache.h | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/block-cache/block_cache.cc b/block-cache/block_cache.cc index 0fbc9db..3b44601 100644 --- a/block-cache/block_cache.cc +++ b/block-cache/block_cache.cc @@ -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(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_); diff --git a/block-cache/block_cache.h b/block-cache/block_cache.h index ff38141..5cf9b27 100644 --- a/block-cache/block_cache.h +++ b/block-cache/block_cache.h @@ -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);