From 19726783cddb0ac3d34a510c083976e6f9661b49 Mon Sep 17 00:00:00 2001
From: "Graham Madarasz (Graham Linden)" <graham@lindenlab.com>
Date: Fri, 23 Aug 2013 14:44:46 -0700
Subject: [PATCH] MAINT-3046 make LLNotifications clear out vecs of
 LLNotificationChannelPtr so singleton cleanup doesn't do things it really
 ought not do

---
 indra/llcommon/llinitparam.h       | 3 ++-
 indra/llcommon/llinstancetracker.h | 1 +
 indra/llui/llnotifications.cpp     | 6 +++++-
 indra/llui/llnotifications.h       | 7 +++++++
 indra/newview/llappviewer.cpp      | 2 ++
 5 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h
index ae836645b90..b3b56321d39 100755
--- a/indra/llcommon/llinitparam.h
+++ b/indra/llcommon/llinitparam.h
@@ -1952,7 +1952,7 @@ namespace LLInitParam
 		class Mandatory : public TypedParam<T, NAME_VALUE_LOOKUP, false>
 		{
 			typedef TypedParam<T, NAME_VALUE_LOOKUP, false>		super_t;
-			typedef Mandatory<T, NAME_VALUE_LOOKUP>										self_t;
+			typedef Mandatory<T, NAME_VALUE_LOOKUP>				self_t;
 			typedef typename super_t::value_t					value_t;
 			typedef typename super_t::default_value_t			default_value_t;
 
@@ -1980,6 +1980,7 @@ namespace LLInitParam
 			static bool validate(const Param* p)
 			{
 				// valid only if provided
+                llassert(p);
 				return static_cast<const self_t*>(p)->isProvided();
 			}
 
diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h
index 361182380ae..7ef7d101db7 100755
--- a/indra/llcommon/llinstancetracker.h
+++ b/indra/llcommon/llinstancetracker.h
@@ -212,6 +212,7 @@ class LLInstanceTracker : public LLInstanceTrackerBase
 	}
 	void remove_()
 	{
+        if (getMap_().find(mInstanceKey) != getMap_().end())
 		getMap_().erase(mInstanceKey);
 	}
 
diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp
index 1789f003b91..0a79f2f5888 100755
--- a/indra/llui/llnotifications.cpp
+++ b/indra/llui/llnotifications.cpp
@@ -1125,7 +1125,7 @@ LLNotificationChannel::LLNotificationChannel(const Params& p)
 	mName(p.name.isProvided() ? p.name : LLUUID::generateNewID().asString())
 {
 	BOOST_FOREACH(const std::string& source, p.sources)
-{
+    {
 		connectToChannel(source);
 	}
 }
@@ -1209,6 +1209,10 @@ LLNotifications::LLNotifications()
 	LLUICtrl::CommitCallbackRegistry::currentRegistrar().add("Notification.Show", boost::bind(&LLNotifications::addFromCallback, this, _2));
 }
 
+void LLNotifications::clear()
+{
+   mDefaultChannels.clear();
+}
 
 // The expiration channel gets all notifications that are cancelled
 bool LLNotifications::expirationFilter(LLNotificationPtr pNotification)
diff --git a/indra/llui/llnotifications.h b/indra/llui/llnotifications.h
index cd3728305e0..3b620084eee 100755
--- a/indra/llui/llnotifications.h
+++ b/indra/llui/llnotifications.h
@@ -874,6 +874,13 @@ class LLNotifications :
 
 	friend class LLSingleton<LLNotifications>;
 public:
+
+    // Needed to clear up RefCounted things prior to actual destruction
+    // as the singleton nature of the class makes them do "bad things"
+    // on at least Mac, if not all 3 platforms
+    //
+    void clear();
+
 	// load all notification descriptions from file
 	// calling more than once will overwrite existing templates
 	// but never delete a template
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 1874cba4a4d..75595f502f9 100755
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -1614,6 +1614,8 @@ bool LLAppViewer::cleanup()
 	//ditch LLVOAvatarSelf instance
 	gAgentAvatarp = NULL;
 
+    LLNotifications::instance().clear();
+
 	// workaround for DEV-35406 crash on shutdown
 	LLEventPumps::instance().reset();
 
-- 
GitLab