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:
parent
0c785a442b
commit
a7b0f02c47
@ -1,6 +1,7 @@
|
|||||||
# Rocksdb Change Log
|
# Rocksdb Change Log
|
||||||
## 6.10.3 (6/16/2020)
|
## 6.10.3 (6/16/2020)
|
||||||
### Bug fix
|
### 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).
|
* 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.
|
* 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
10
env/fs_posix.cc
vendored
@ -241,6 +241,8 @@ class PosixFileSystem : public FileSystem {
|
|||||||
s = IOError("while mmap file for read", fname, errno);
|
s = IOError("while mmap file for read", fname, errno);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (options.use_direct_reads && !options.use_mmap_reads) {
|
if (options.use_direct_reads && !options.use_mmap_reads) {
|
||||||
@ -889,14 +891,16 @@ class PosixFileSystem : public FileSystem {
|
|||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
return IOError("While open for IsDirectory()", path, errno);
|
return IOError("While open for IsDirectory()", path, errno);
|
||||||
}
|
}
|
||||||
|
IOStatus io_s;
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
if (fstat(fd, &sbuf) < 0) {
|
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);
|
*is_dir = S_ISDIR(sbuf.st_mode);
|
||||||
}
|
}
|
||||||
return IOStatus::OK();
|
return io_s;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOptions OptimizeForLogWrite(const FileOptions& file_options,
|
FileOptions OptimizeForLogWrite(const FileOptions& file_options,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user