diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index b38f551e0..92ea581f0 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5172,9 +5172,12 @@ class ScopedPrematureExitFile { // create the file with a single "0" character in it. I/O // errors are ignored as there's nothing better we can do and we // don't want to fail the test because of this. - FILE* pfile = posix::FOpen(premature_exit_filepath_.c_str(), "w"); - fwrite("0", 1, 1, pfile); - fclose(pfile); + if (FILE* pfile = posix::FOpen(premature_exit_filepath_.c_str(), "w")) { + fwrite("0", 1, 1, pfile); + fclose(pfile); + } else { + premature_exit_filepath_.clear(); + } } } @@ -5192,7 +5195,7 @@ class ScopedPrematureExitFile { } private: - const std::string premature_exit_filepath_; + std::string premature_exit_filepath_; ScopedPrematureExitFile(const ScopedPrematureExitFile&) = delete; ScopedPrematureExitFile& operator=(const ScopedPrematureExitFile&) = delete;