diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index ac90786a0..5256493b1 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5173,8 +5173,10 @@ class ScopedPrematureExitFile { // 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 (pfile != nullptr) { + fwrite("0", 1, 1, pfile); + fclose(pfile); + } } }