Merge pull request #5039 from alvinjaison:fix/premature-exit-file-null-deref

PiperOrigin-RevId: 952921022
Change-Id: Ic7c587ad76eb56a9995043c86ee09c64afd52504
This commit is contained in:
Copybara-Service
2026-07-23 13:21:28 -07:00
+5 -2
View File
@@ -5172,9 +5172,12 @@ class ScopedPrematureExitFile {
// create the file with a single "0" character in it. I/O // 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 // errors are ignored as there's nothing better we can do and we
// don't want to fail the test because of this. // don't want to fail the test because of this.
FILE* pfile = posix::FOpen(premature_exit_filepath_.c_str(), "w"); if (FILE* pfile = posix::FOpen(premature_exit_filepath_.c_str(), "w")) {
fwrite("0", 1, 1, pfile); fwrite("0", 1, 1, pfile);
fclose(pfile); fclose(pfile);
} else {
premature_exit_filepath_.clear();
}
} }
} }
@@ -5192,7 +5195,7 @@ class ScopedPrematureExitFile {
} }
private: private:
const std::string premature_exit_filepath_; std::string premature_exit_filepath_;
ScopedPrematureExitFile(const ScopedPrematureExitFile&) = delete; ScopedPrematureExitFile(const ScopedPrematureExitFile&) = delete;
ScopedPrematureExitFile& operator=(const ScopedPrematureExitFile&) = delete; ScopedPrematureExitFile& operator=(const ScopedPrematureExitFile&) = delete;