diff --git a/atom/common/crash_reporter/crash_reporter_win.cc b/atom/common/crash_reporter/crash_reporter_win.cc index 7ce61d6971..3261f9c9c6 100644 --- a/atom/common/crash_reporter/crash_reporter_win.cc +++ b/atom/common/crash_reporter/crash_reporter_win.cc @@ -138,7 +138,8 @@ void UnregisterNonABICompliantCodeRange(void* start) { } // namespace CrashReporterWin::CrashReporterWin() - : skip_system_crash_handler_(false) { + : skip_system_crash_handler_(false), + code_range_registered_(false) { } CrashReporterWin::~CrashReporterWin() { @@ -189,19 +190,20 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name, LOG(ERROR) << "Cannot initialize out-of-process crash handler"; #ifdef _WIN64 - bool registered = false; // Hook up V8 to breakpad. - { + if (!code_range_registered_) { + code_range_registered_ = true; // gin::Debug::SetCodeRangeCreatedCallback only runs the callback when // Isolate is just created, so we have to manually run following code here. void* code_range = nullptr; size_t size = 0; v8::Isolate::GetCurrent()->GetCodeRange(&code_range, &size); - if (code_range && size) - registered = RegisterNonABICompliantCodeRange(code_range, size); + if (code_range && size && + RegisterNonABICompliantCodeRange(code_range, size)) { + gin::Debug::SetCodeRangeDeletedCallback( + UnregisterNonABICompliantCodeRange); + } } - if (registered) - gin::Debug::SetCodeRangeDeletedCallback(UnregisterNonABICompliantCodeRange); #endif } diff --git a/atom/common/crash_reporter/crash_reporter_win.h b/atom/common/crash_reporter/crash_reporter_win.h index 93be8af32c..806c3de317 100644 --- a/atom/common/crash_reporter/crash_reporter_win.h +++ b/atom/common/crash_reporter/crash_reporter_win.h @@ -62,6 +62,7 @@ class CrashReporterWin : public CrashReporter { google_breakpad::CustomClientInfo custom_info_; bool skip_system_crash_handler_; + bool code_range_registered_; std::unique_ptr breakpad_; DISALLOW_COPY_AND_ASSIGN(CrashReporterWin); diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index b4f63fe1ef..16806c7102 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -88,5 +88,19 @@ describe('crash-reporter module', function () { }) }, /companyName is a required option to crashReporter\.start/) }) + + it('can be called multiple times', function () { + assert.doesNotThrow(function () { + crashReporter.start({ + companyName: 'Umbrella Corporation', + submitURL: 'http://127.0.0.1/crashes' + }) + + crashReporter.start({ + companyName: 'Umbrella Corporation 2', + submitURL: 'http://127.0.0.1/more-crashes' + }) + }) + }) }) })