From 0450358df398054b24f0c84cf52bc835c0c21b37 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Thu, 23 Feb 2012 18:46:44 +0100 Subject: [PATCH] Clean up after Linden Lab --- indra/llcommon/llevents.cpp | 32 +++++++++++++++++++++++--------- indra/llcommon/llevents.h | 2 ++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/indra/llcommon/llevents.cpp b/indra/llcommon/llevents.cpp index db1ea4792..9bc61ccb5 100644 --- a/indra/llcommon/llevents.cpp +++ b/indra/llcommon/llevents.cpp @@ -244,17 +244,31 @@ void LLEventPumps::unregister(const LLEventPump& pump) } } +//static +bool LLEventPumps::sDeleted; + +//static +void LLEventPumps::maybe_unregister(const LLEventPump& pump) +{ + if (!sDeleted) + { + LLEventPumps::instance().unregister(pump); + } +} + LLEventPumps::~LLEventPumps() { - // On destruction, delete every LLEventPump we instantiated (via - // obtain()). CAREFUL: deleting an LLEventPump calls its destructor, which - // calls unregister(), which removes that LLEventPump instance from - // mOurPumps. So an iterator loop over mOurPumps to delete contained - // LLEventPump instances is dangerous! Instead, delete them one at a time - // until mOurPumps is empty. - while (! mOurPumps.empty()) + // Deleting an LLEventPump calls its destructor, which calls maybe_unregister(), + // which would try to remove that LLEventPump instance from a NEWLY created LLEventPumps + // singleton (as we're already being destructed). Therefore, mark that we're not + // home anymore... --Aleric + sDeleted = true; + + // Subsequently we can delete every LLEventPump we instantiated (via obtain()). + // We're not clearing mPumpMap or mOurPumps here... their destructors will. + for (LLEventPumps::PumpSet::iterator pump = mOurPumps.begin(); pump != mOurPumps.end(); ++pump) { - delete *mOurPumps.begin(); + delete *pump; } } @@ -280,7 +294,7 @@ LLEventPump::LLEventPump(const std::string& name, bool tweak): LLEventPump::~LLEventPump() { // Unregister this doomed instance from LLEventPumps - LLEventPumps::instance().unregister(*this); + LLEventPumps::maybe_unregister(*this); } // static data member diff --git a/indra/llcommon/llevents.h b/indra/llcommon/llevents.h index 3ada48eb6..4f8fb1d3f 100644 --- a/indra/llcommon/llevents.h +++ b/indra/llcommon/llevents.h @@ -238,6 +238,8 @@ private: * Unregister a doomed LLEventPump instance (internal) */ void unregister(const LLEventPump&); + static bool sDeleted; + static void maybe_unregister(const LLEventPump&); private: LLEventPumps();