[block-cache] fix potential file descriptor leak
Encapsulate file descriptor into an object, to ensure that an fd will be closed properly while exception raised, e.g., the block_cache throws exception during the block_manager's construction.
This commit is contained in:
@ -136,11 +136,12 @@ namespace persistent_data {
|
||||
|
||||
private:
|
||||
uint64_t choose_cache_size(block_address nr_blocks) const;
|
||||
int open_or_create_block_file(std::string const &path, off_t file_size,
|
||||
mode m, bool excl);
|
||||
file_utils::file_descriptor open_or_create_block_file(std::string const &path,
|
||||
off_t file_size,
|
||||
mode m, bool excl);
|
||||
void check(block_address b) const;
|
||||
|
||||
int fd_;
|
||||
file_utils::file_descriptor fd_;
|
||||
mutable block_cache bc_;
|
||||
unsigned superblock_ref_count_;
|
||||
};
|
||||
|
@ -154,7 +154,7 @@ namespace persistent_data {
|
||||
}
|
||||
|
||||
template <uint32_t BlockSize>
|
||||
int
|
||||
file_utils::file_descriptor
|
||||
block_manager<BlockSize>::open_or_create_block_file(std::string const &path, off_t file_size, mode m, bool excl)
|
||||
{
|
||||
switch (m) {
|
||||
|
Reference in New Issue
Block a user