Skip to content

Commit

Permalink
Initialize KSCrashMonitor_CPPException stackCursor
Browse files Browse the repository at this point in the history
Our __cxa_throw override is only called if the exception is thrown
from the same image as our __cxa_throw lives in, e.g. the main app
if KSCrash is linked in as a static library.

In cases where it's not called the advanceCursor and resetCursor
members of the KSStackCursor are 0, resulting in a crash during
crash handling.

By always initializing the stackCursor we at least ensure that we
don't crash during reporting, even if the result is an empty
stack trace for that thread.
  • Loading branch information
torarnv committed Mar 21, 2017
1 parent 82d1366 commit 60d493b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Source/KSCrash/Recording/Monitors/KSCrashMonitor_CPPException.cpp
Expand Up @@ -184,13 +184,25 @@ catch(TYPE value)\
#pragma mark - Public API -
// ============================================================================

static void initialize()
{
static bool isInitialized = false;
if(!isInitialized)
{
isInitialized = true;
kssc_initCursor(&g_stackCursor, 0, 0);
}
}

static void setEnabled(bool isEnabled)
{
if(isEnabled != g_isEnabled)
{
g_isEnabled = isEnabled;
if(isEnabled)
{
initialize();

ksid_generate(g_eventID);
g_originalTerminateHandler = std::set_terminate(CPPExceptionTerminate);
}
Expand Down

0 comments on commit 60d493b

Please sign in to comment.