crash: Clean up the temp file used in GetLogContents.
On R63, some big log dumps can fill up /tmp and make the OS unstable.
R64 won't be affected since it introduces sandboxing and unmounts
its own /tmp each time. That said, this CL is still safe for ToT (R64)
and needs to land and be baked on R64 before cherry-picked to R63.
BUG=chromium:789052
TEST=/tmp is not filled up after repeated crashes.
TEST=cros_run_unit_tests --packages crash-reporter
Change-Id: I0a54fdac9a150cc37d50f72f6095babb79528bd5
Reviewed-on: https://chromium-review.googlesource.com/798550
Commit-Ready: Kazuhiro Inaba <kinaba@chromium.org>
Tested-by: Kazuhiro Inaba <kinaba@chromium.org>
Reviewed-by: Ilja H. Friedel <ihf@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
(cherry picked from commit 7244202cb543ec33fa1e6b3908d05dc30d33d1a8)
Reviewed-on: https://chromium-review.googlesource.com/802835
Trybot-Ready: Kazuhiro Inaba <kinaba@chromium.org>
Reviewed-by: Kazuhiro Inaba <kinaba@chromium.org>
Commit-Queue: Kazuhiro Inaba <kinaba@chromium.org>
diff --git a/crash-reporter/crash_collector.cc b/crash-reporter/crash_collector.cc
index a29ba19..e627223 100644
--- a/crash-reporter/crash_collector.cc
+++ b/crash-reporter/crash_collector.cc
@@ -526,9 +526,11 @@
}
std::string log_contents;
- if (!base::ReadFileToStringWithMaxSize(raw_output_file,
- &log_contents,
- max_log_size_)) {
+ const bool fully_read = base::ReadFileToStringWithMaxSize(
+ raw_output_file, &log_contents, max_log_size_);
+ base::DeleteFile(raw_output_file, false);
+
+ if (!fully_read) {
if (log_contents.empty()) {
LOG(WARNING) << "Failed to read raw log contents.";
return false;