Close file to avoid file-descriptor leakage (#6936)

Summary:
When operation on an open file descriptor fails, we should close the file descriptor.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6936

Test Plan: make check

Reviewed By: pdillinger

Differential Revision: D21885458

Pulled By: riversand963

fbshipit-source-id: ba077a76b256a8537f21e22e4ec198f45390bf50
This commit is contained in:
Yanqin Jin 2020-06-04 14:19:05 -07:00
parent 0c785a442b
commit a7b0f02c47
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,7 @@
# Rocksdb Change Log
## 6.10.3 (6/16/2020)
### Bug fix
* Fix potential file descriptor leakage in PosixEnv's IsDirectory() and NewRandomAccessFile().
* Best-efforts recovery ignores CURRENT file completely. If CURRENT file is missing during recovery, best-efforts recovery still proceeds with MANIFEST file(s).
* In best-efforts recovery, an error that is not Corruption or IOError::kNotFound or IOError::kPathNotFound will be overwritten silently. Fix this by checking all non-ok cases and return early.

10
env/fs_posix.cc vendored
View File

@ -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,