From b150081d04b1fc2c4f44cc4a1f252ac1272b2274 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Thu, 14 Jul 2016 18:48:20 +0800 Subject: [PATCH] kv/MemDB: fix fd leak Also translate the error message to the output properly. Signed-off-by: xie xingguo --- src/kv/MemDB.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/kv/MemDB.cc b/src/kv/MemDB.cc index ce6c5ef952c54..5135e6d1e295d 100644 --- a/src/kv/MemDB.cc +++ b/src/kv/MemDB.cc @@ -94,16 +94,21 @@ void MemDB::_load() */ int fd = TEMP_FAILURE_RETRY(::open(_get_data_fn().c_str(), O_RDONLY)); if (fd < 0) { + int err = errno; std::ostringstream oss; - oss << "can't open " << _get_data_fn().c_str() << ": " << std::endl; + oss << "can't open " << _get_data_fn().c_str() << ": " + << cpp_strerror(err) << std::endl; return; } struct stat st; memset(&st, 0, sizeof(st)); if (::fstat(fd, &st) < 0) { + int err = errno; std::ostringstream oss; - oss << "can't stat file " << _get_data_fn().c_str() << ": " << std::endl; + oss << "can't stat file " << _get_data_fn().c_str() << ": " + << cpp_strerror(err) << std::endl; + VOID_TEMP_FAILURE_RETRY(::close(fd)); return; } -- 2.39.5