1
0
Fork 0

ErrorReporter: fix a crash on exit found by ASan

If we exit without shutdown()-ing the error report, ensure the
error logging callback is cleaned up.
This commit is contained in:
James Turner 2021-06-08 17:46:05 +01:00
parent 81e12d7c2e
commit 6a7de07fda
2 changed files with 14 additions and 0 deletions

View file

@ -213,6 +213,7 @@ public:
using OccurrenceVec = std::vector<ErrorOcurrence>;
std::unique_ptr<RecentLogCallback> _logCallback;
bool _logCallbackRegistered = false;
string _terrasyncPathPrefix;
string _fgdataPathPrefix;
@ -709,6 +710,15 @@ ErrorReporter::ErrorReporter() : d(new ErrorReporterPrivate)
"/scenery/use-vpb"};
}
ErrorReporter::~ErrorReporter()
{
// if we are deleted withut being shutdown(), ensure we clean
// up our logging callback
if (d->_logCallbackRegistered) {
sglog().removeCallback(d->_logCallback.get());
}
}
void ErrorReporter::bind()
{
SGPropertyNode_ptr n = fgGetNode("/sim/error-report", true);
@ -742,6 +752,7 @@ void ErrorReporter::preinit()
});
sglog().addCallback(d->_logCallback.get());
d->_logCallbackRegistered = true;
}
void ErrorReporter::init()
@ -758,6 +769,7 @@ void ErrorReporter::init()
simgear::setFailureCallback(simgear::FailureCallback());
simgear::setErrorContextCallback(simgear::ContextCallback());
sglog().removeCallback(d->_logCallback.get());
d->_logCallbackRegistered = false;
return;
}
@ -874,6 +886,7 @@ void ErrorReporter::shutdown()
globals->get_commands()->removeCommand("save-error-report-data");
globals->get_commands()->removeCommand("show-error-report");
sglog().removeCallback(d->_logCallback.get());
d->_logCallbackRegistered = false;
}
}

View file

@ -30,6 +30,7 @@ class ErrorReporter : public SGSubsystem
{
public:
ErrorReporter();
~ErrorReporter();
void preinit();