Fix crash in PosixWritableFile::Close() when fstat() fails

Summary:
We had a crash in this code: `fstat()` failed; `file_stats` contained garbage, in particular `file_stats.st_blksize == 6`; the expression `file_stats.st_blocks / (file_stats.st_blksize / 512)` divided by zero.
Closes https://github.com/facebook/rocksdb/pull/2420

Differential Revision: D5216110

Pulled By: al13n321

fbshipit-source-id: 6d8fc5e7c4f98c1139e68c7829ebdbac68b0fce0
This commit is contained in:
Mike Kolupaev 2017-06-08 19:54:00 -07:00 committed by Facebook Github Bot
parent 6d0f22e42f
commit bc09c8a0db

5
env/io_posix.cc vendored
View File

@ -800,10 +800,11 @@ Status PosixWritableFile::Close() {
// While we work with Travis-CI team to figure out if this is a
// quirk of Docker/AUFS, we will comment this out.
struct stat file_stats;
fstat(fd_, &file_stats);
int result = fstat(fd_, &file_stats);
// After ftruncate, we check whether ftruncate has the correct behavior.
// If not, we should hack it with FALLOC_FL_PUNCH_HOLE
if ((file_stats.st_size + file_stats.st_blksize - 1) /
if (result == 0 &&
(file_stats.st_size + file_stats.st_blksize - 1) /
file_stats.st_blksize !=
file_stats.st_blocks / (file_stats.st_blksize / 512)) {
IOSTATS_TIMER_GUARD(allocate_nanos);