From 5c52cdc25513a1cfea8e74ef90efc25410b4191e Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 22 Apr 2020 10:55:41 +0100 Subject: [PATCH] Fix for crash on reset: https://sourceforge.net/p/flightgear/codetickets/2217/ Ensure that subsystem lookup during its own removal, returns nullptr. Otherwise we cache an about-to-be dead pointer, which is Bad (TM) --- simgear/structure/subsystem_mgr.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/simgear/structure/subsystem_mgr.cxx b/simgear/structure/subsystem_mgr.cxx index 6ceff02e..a4ea8270 100644 --- a/simgear/structure/subsystem_mgr.cxx +++ b/simgear/structure/subsystem_mgr.cxx @@ -647,6 +647,14 @@ SGSubsystemGroup::remove_subsystem(const string &name) // found it, great const auto sub = (*it)->subsystem; + // ensure we clear the name during shutdown. This ensures that + // a lookup during shutdown fails, which is the desired behaviour. + // for an example see: https://sourceforge.net/p/flightgear/codetickets/2217/ + // where we looked up Nasal during Nasal shutdown + // without this, the SubsystemMgr re-caches a dead pointer + // after doing its clear() + (*it)->name.clear(); + if (_state != State::INVALID) { // transition out correctly if ((_state >= State::INIT) && (_state < State::SHUTDOWN)) {