diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-09-27 00:17:54 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-09-27 00:17:54 +0000 |
commit | 1806fd40d4128eb3d2419256faace4a04026e9c3 (patch) | |
tree | 710160fffc140e02d6b9f5a83ff854dc5c82464e | |
parent | ef953dc6af4c2a17508e0a81a16ba089404ea90d (diff) | |
parent | 1a05046c862d49d5e172657a5f206b20ade3598a (diff) | |
download | art-1806fd40d4128eb3d2419256faace4a04026e9c3.tar.gz |
Merge "Ensure the oat/vdex file is erased if we fail to truncate" into oc-mr1-dev
-rw-r--r-- | dex2oat/dex2oat.cc | 11 | ||||
-rw-r--r-- | runtime/base/unix_file/fd_file.cc | 6 |
2 files changed, 10 insertions, 7 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 8fc8f4b8e7..5277f3a968 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -1348,7 +1348,7 @@ class Dex2Oat FINAL { DCHECK(!oat_filenames_.empty()); for (const char* oat_filename : oat_filenames_) { std::unique_ptr<File> oat_file(OS::CreateEmptyFile(oat_filename)); - if (oat_file.get() == nullptr) { + if (oat_file == nullptr) { PLOG(ERROR) << "Failed to create oat file: " << oat_filename; return false; } @@ -1378,7 +1378,7 @@ class Dex2Oat FINAL { vdex_files_.push_back(std::move(vdex_file)); } else { std::unique_ptr<File> vdex_file(OS::CreateEmptyFile(vdex_filename.c_str())); - if (vdex_file.get() == nullptr) { + if (vdex_file == nullptr) { PLOG(ERROR) << "Failed to open vdex file: " << vdex_filename; return false; } @@ -1392,13 +1392,15 @@ class Dex2Oat FINAL { } } else { std::unique_ptr<File> oat_file(new File(oat_fd_, oat_location_, /* check_usage */ true)); - if (oat_file.get() == nullptr) { + if (oat_file == nullptr) { PLOG(ERROR) << "Failed to create oat file: " << oat_location_; return false; } oat_file->DisableAutoClose(); if (oat_file->SetLength(0) != 0) { PLOG(WARNING) << "Truncating oat file " << oat_location_ << " failed."; + oat_file->Erase(); + return false; } oat_files_.push_back(std::move(oat_file)); @@ -1427,7 +1429,7 @@ class Dex2Oat FINAL { DCHECK_NE(output_vdex_fd_, -1); std::string vdex_location = ReplaceFileExtension(oat_location_, "vdex"); std::unique_ptr<File> vdex_file(new File(output_vdex_fd_, vdex_location, /* check_usage */ true)); - if (vdex_file.get() == nullptr) { + if (vdex_file == nullptr) { PLOG(ERROR) << "Failed to create vdex file: " << vdex_location; return false; } @@ -1437,6 +1439,7 @@ class Dex2Oat FINAL { } else { if (vdex_file->SetLength(0) != 0) { PLOG(ERROR) << "Truncating vdex file " << vdex_location << " failed."; + vdex_file->Erase(); return false; } } diff --git a/runtime/base/unix_file/fd_file.cc b/runtime/base/unix_file/fd_file.cc index 20e0cfa8b1..cef2134fc1 100644 --- a/runtime/base/unix_file/fd_file.cc +++ b/runtime/base/unix_file/fd_file.cc @@ -69,7 +69,7 @@ void FdFile::Destroy() { if (guard_state_ < GuardState::kClosed) { LOG(ERROR) << "File " << file_path_ << " wasn't explicitly closed before destruction."; } - CHECK_GE(guard_state_, GuardState::kClosed); + DCHECK_GE(guard_state_, GuardState::kClosed); } if (auto_close_ && fd_ != -1) { if (Close() != 0) { @@ -134,7 +134,7 @@ bool FdFile::Open(const std::string& path, int flags) { bool FdFile::Open(const std::string& path, int flags, mode_t mode) { static_assert(O_RDONLY == 0, "Readonly flag has unexpected value."); - CHECK_EQ(fd_, -1) << path; + DCHECK_EQ(fd_, -1) << path; read_only_mode_ = ((flags & O_ACCMODE) == O_RDONLY); fd_ = TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode)); if (fd_ == -1) { @@ -157,7 +157,7 @@ int FdFile::Close() { // Test here, so the file is closed and not leaked. if (kCheckSafeUsage) { - CHECK_GE(guard_state_, GuardState::kFlushed) << "File " << file_path_ + DCHECK_GE(guard_state_, GuardState::kFlushed) << "File " << file_path_ << " has not been flushed before closing."; moveUp(GuardState::kClosed, nullptr); } |