os/LFNIndex: use FDCloser for fsync_dir

This prevents an fd leak when maybe_inject_failure() throws an exception.

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2014-07-21 13:45:21 -07:00
parent 6fb3260d59
commit 3ec9a42b47

View File

@ -171,9 +171,9 @@ int LFNIndex::fsync_dir(const vector<string> &path)
int fd = ::open(get_full_path_subdir(path).c_str(), O_RDONLY);
if (fd < 0)
return -errno;
FDCloser f(fd);
maybe_inject_failure();
int r = ::fsync(fd);
VOID_TEMP_FAILURE_RETRY(::close(fd));
maybe_inject_failure();
if (r < 0)
return -errno;