[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:
Ming-Hung Tsai committed 2020-02-23 15:41:16 +08:00
1 parent c85ea5ef76
commit 955e11bc28
9 files changed
+42 -32

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ TEST(BCacheTests, cleaned_on_demand)
unsigned const NR_BLOCKS = 16;
temp_file tmp("bcache_t", 1);
int fd = open(tmp.get_path().c_str(), O_RDWR | O_DIRECT, 0666);
file_utils::file_descriptor fd(tmp.get_path().c_str(), O_RDWR | O_DIRECT);
uint64_t bs = 8;
block_cache bc(fd, bs, 64, (bs << SECTOR_SHIFT) * NR_BLOCKS);