diff --git a/HISTORY.md b/HISTORY.md index 0edb91016..bde805fb4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,6 +11,7 @@ * Let best-efforts recovery ignore corrupted files during table loading. * Fix corrupt key read from ingested file when iterator direction switches from reverse to forward at a key that is a prefix of another key in the same file. It is only possible in files with a non-zero global seqno. * Fix abnormally large estimate from GetApproximateSizes when a range starts near the end of one SST file and near the beginning of another. Now GetApproximateSizes consistently and fairly includes the size of SST metadata in addition to data blocks, attributing metadata proportionally among the data blocks based on their size. +* Fix potential file descriptor leakage in PosixEnv's IsDirectory() and NewRandomAccessFile(). ### Public API Change * Flush(..., column_family) may return Status::ColumnFamilyDropped() instead of Status::InvalidArgument() if column_family is dropped while processing the flush request. diff --git a/env/fs_posix.cc b/env/fs_posix.cc index 92808eaa2..b00db6f67 100644 --- a/env/fs_posix.cc +++ b/env/fs_posix.cc @@ -241,6 +241,8 @@ class PosixFileSystem : public FileSystem { s = IOError("while mmap file for read", fname, errno); close(fd); } + } else { + close(fd); } } else { if (options.use_direct_reads && !options.use_mmap_reads) { @@ -889,14 +891,16 @@ class PosixFileSystem : public FileSystem { if (fd < 0) { return IOError("While open for IsDirectory()", path, errno); } + IOStatus io_s; struct stat sbuf; if (fstat(fd, &sbuf) < 0) { - return IOError("While doing stat for IsDirectory()", path, errno); + io_s = IOError("While doing stat for IsDirectory()", path, errno); } - if (nullptr != is_dir) { + close(fd); + if (io_s.ok() && nullptr != is_dir) { *is_dir = S_ISDIR(sbuf.st_mode); } - return IOStatus::OK(); + return io_s; } FileOptions OptimizeForLogWrite(const FileOptions& file_options,