diff --git a/client/crashpad_client_ios.cc b/client/crashpad_client_ios.cc index 01d34845..467cc0cf 100644 --- a/client/crashpad_client_ios.cc +++ b/client/crashpad_client_ios.cc @@ -106,13 +106,22 @@ class CrashHandler : public Thread, void DumpWithoutCrash(NativeCPUContext* context, bool process_dump) { INITIALIZATION_STATE_DCHECK_VALID(initialized_); - internal::InProcessHandler::ScopedAlternateWriter scoper( - &in_process_handler_); - if (scoper.Open()) { - DumpWithContext(context); - if (process_dump) { - in_process_handler_.ProcessIntermediateDump(scoper.path()); + base::FilePath path; + { + // Ensure ScopedAlternateWriter's destructor is invoked before processing + // the dump, or else any crashes handled during dump processing cannot be + // written. + internal::InProcessHandler::ScopedAlternateWriter scoper( + &in_process_handler_); + if (!scoper.Open()) { + LOG(ERROR) << "Could not open writer, ignoring dump request."; + return; } + DumpWithContext(context); + path = scoper.path(); + } + if (process_dump) { + in_process_handler_.ProcessIntermediateDump(path); } } diff --git a/client/ios_handler/in_process_handler.cc b/client/ios_handler/in_process_handler.cc index 6058e3b3..ea86f39e 100644 --- a/client/ios_handler/in_process_handler.cc +++ b/client/ios_handler/in_process_handler.cc @@ -24,6 +24,7 @@ #include "minidump/minidump_file_writer.h" #include "util/file/directory_reader.h" #include "util/file/filesystem.h" +#include "util/ios/raw_logging.h" namespace { @@ -116,6 +117,10 @@ void InProcessHandler::DumpExceptionFromSignal( siginfo_t* siginfo, ucontext_t* context) { INITIALIZATION_STATE_DCHECK_VALID(initialized_); + if (!writer_) { + CRASHPAD_RAW_LOG("Cannot DumpExceptionFromSignal without writer_"); + return; + } { ScopedReport report(writer_.get(), system_data, annotations_); InProcessIntermediateDumpHandler::WriteExceptionFromSignal( @@ -135,6 +140,10 @@ void InProcessHandler::DumpExceptionFromMachException( ConstThreadState old_state, mach_msg_type_number_t old_state_count) { INITIALIZATION_STATE_DCHECK_VALID(initialized_); + if (!writer_) { + CRASHPAD_RAW_LOG("Cannot DumpExceptionFromMachException without writer_"); + return; + } { ScopedReport report(writer_.get(), system_data, annotations_); InProcessIntermediateDumpHandler::WriteExceptionFromMachException( @@ -155,6 +164,12 @@ void InProcessHandler::DumpExceptionFromNSExceptionFrames( const IOSSystemDataCollector& system_data, const uint64_t* frames, const size_t num_frames) { + INITIALIZATION_STATE_DCHECK_VALID(initialized_); + if (!writer_) { + CRASHPAD_RAW_LOG( + "Cannot DumpExceptionFromNSExceptionFrames without writer_"); + return; + } { ScopedReport report( writer_.get(), system_data, annotations_, frames, num_frames); @@ -318,6 +333,7 @@ InProcessHandler::ScopedReport::ScopedReport( frames_(frames), num_frames_(num_frames), rootMap_(writer) { + DCHECK(writer); InProcessIntermediateDumpHandler::WriteHeader(writer); InProcessIntermediateDumpHandler::WriteProcessInfo(writer, annotations); InProcessIntermediateDumpHandler::WriteSystemInfo(writer, system_data);