Bug 1247978 - Ensure minidump header gets written during crash dump on Linux r=ted
authorJames Willcox <snorp@snorp.net>
Fri, 12 Feb 2016 11:06:31 -0600
changeset 331310 22d3b72e28e44f0d6cf6f5972bf8919bcd7f8689
parent 331309 99dae519223a2e4f6c0df9824b5117726afbd98d
child 331311 f2e9daa91f025e42ac0306bb07fcb5dc75cd80ed
push id10956
push userjolesen@mozilla.com
push dateTue, 16 Feb 2016 19:12:12 +0000
reviewersted
bugs1247978
milestone47.0a1
Bug 1247978 - Ensure minidump header gets written during crash dump on Linux r=ted
toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/minidump_writer.cc
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/minidump_writer.cc
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/minidump_writer.cc
@@ -163,29 +163,35 @@ class MinidumpWriter {
     dumper_->ThreadsResume();
   }
 
   bool Dump() {
     // A minidump file contains a number of tagged streams. This is the number
     // of stream which we write.
     unsigned kNumWriters = 13;
 
-    TypedMDRVA<MDRawHeader> header(&minidump_writer_);
     TypedMDRVA<MDRawDirectory> dir(&minidump_writer_);
-    if (!header.Allocate())
-      return false;
-    if (!dir.AllocateArray(kNumWriters))
-      return false;
-    my_memset(header.get(), 0, sizeof(MDRawHeader));
+    {
+      // Ensure the header gets flushed, as that happens in the destructor.
+      // If we crash somewhere below, we should have a mostly-intact dump
+      TypedMDRVA<MDRawHeader> header(&minidump_writer_);
+      if (!header.Allocate())
+        return false;
 
-    header.get()->signature = MD_HEADER_SIGNATURE;
-    header.get()->version = MD_HEADER_VERSION;
-    header.get()->time_date_stamp = time(NULL);
-    header.get()->stream_count = kNumWriters;
-    header.get()->stream_directory_rva = dir.position();
+      if (!dir.AllocateArray(kNumWriters))
+        return false;
+
+      my_memset(header.get(), 0, sizeof(MDRawHeader));
+
+      header.get()->signature = MD_HEADER_SIGNATURE;
+      header.get()->version = MD_HEADER_VERSION;
+      header.get()->time_date_stamp = time(NULL);
+      header.get()->stream_count = kNumWriters;
+      header.get()->stream_directory_rva = dir.position();
+    }
 
     unsigned dir_index = 0;
     MDRawDirectory dirent;
 
     if (!WriteThreadListStream(&dirent))
       return false;
     dir.CopyIndex(dir_index++, &dirent);