From 1033c9d67f6bf3fd317bc2e6a6990e2b7e5d80c8 Mon Sep 17 00:00:00 2001
From: maksymsproductengine <maksymsproductengine@lindenlab.com>
Date: Wed, 5 Feb 2014 20:45:09 +0200
Subject: [PATCH] MAINT-3555 crash in LLPanel::~LLPanel() on shutdown:  -
 memory leaks fixing;

---
 indra/llcommon/llerror.cpp                   | 68 +++++++++++---------
 indra/llcrashlogger/llcrashlogger.cpp        |  5 +-
 indra/llmessage/llhttpsender.cpp             |  3 +-
 indra/llmessage/llhttpsender.h               |  2 +-
 indra/llui/llpanel.h                         |  9 ++-
 indra/newview/llappviewerwin32.cpp           |  8 ---
 indra/newview/llcofwearables.cpp             |  2 +-
 indra/newview/llfloatercamera.cpp            |  2 +-
 indra/newview/llfloaterpreference.cpp        |  6 +-
 indra/newview/llfloatersocial.cpp            |  8 +--
 indra/newview/lloutfitslist.cpp              |  2 +-
 indra/newview/llpanelblockedlist.cpp         |  2 +-
 indra/newview/llpaneleditwearable.cpp        |  2 +-
 indra/newview/llpanelgroup.cpp               |  2 +-
 indra/newview/llpanelgroupgeneral.cpp        |  2 +-
 indra/newview/llpanelgrouplandmoney.cpp      |  2 +-
 indra/newview/llpanelgroupnotices.cpp        |  2 +-
 indra/newview/llpanelgrouproles.cpp          |  8 +--
 indra/newview/llpanelhome.cpp                |  2 +-
 indra/newview/llpanellandmarkinfo.cpp        |  2 +-
 indra/newview/llpanelmaininventory.cpp       |  2 +-
 indra/newview/llpanelmarketplaceinbox.cpp    |  2 +-
 indra/newview/llpanelme.cpp                  |  2 +-
 indra/newview/llpaneloutfitedit.cpp          |  2 +-
 indra/newview/llpaneloutfitsinventory.cpp    |  2 +-
 indra/newview/llpanelpeople.cpp              |  2 +-
 indra/newview/llpanelpicks.cpp               |  2 +-
 indra/newview/llpanelplaceprofile.cpp        |  2 +-
 indra/newview/llpanelplaces.cpp              |  2 +-
 indra/newview/llpanelsnapshotinventory.cpp   |  2 +-
 indra/newview/llpanelsnapshotlocal.cpp       |  2 +-
 indra/newview/llpanelsnapshotoptions.cpp     |  2 +-
 indra/newview/llpanelsnapshotpostcard.cpp    |  2 +-
 indra/newview/llpanelsnapshotprofile.cpp     |  2 +-
 indra/newview/llpanelvoicedevicesettings.cpp |  2 +-
 indra/newview/llpanelvoiceeffect.cpp         |  2 +-
 indra/newview/llpanelwearing.cpp             |  2 +-
 indra/newview/llpopupview.cpp                |  2 +-
 indra/newview/llprogressview.cpp             |  2 +-
 indra/newview/llsidepanelappearance.cpp      |  2 +-
 indra/newview/llsidepanelinventory.cpp       |  2 +-
 indra/newview/llsidepaneliteminfo.cpp        |  2 +-
 indra/newview/llsidepaneltaskinfo.cpp        |  2 +-
 indra/newview/lltool.h                       |  2 +-
 indra/newview/lltoolcomp.cpp                 |  2 +-
 45 files changed, 94 insertions(+), 95 deletions(-)

diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp
index 853f279c95a..925fca1b4be 100755
--- a/indra/llcommon/llerror.cpp
+++ b/indra/llcommon/llerror.cpp
@@ -207,6 +207,10 @@ namespace {
 #endif
 }
 
+namespace LLError
+{
+	void clean();
+}
 
 namespace
 {
@@ -352,7 +356,11 @@ namespace
 		Globals()
 			:	messageStreamInUse(false)
 			{ }
-		
+
+		~Globals()
+		{
+			LLError::clean();
+		}
 	};
 
 	void Globals::addCallSite(LLError::CallSite& site)
@@ -380,8 +388,9 @@ namespace
 		   is.
 		   See C++ FAQ Lite, sections 10.12 through 10.14
 		*/
-		static Globals* globals = new Globals;		
-		return *globals;
+
+		static Globals globals;
+		return globals;
 	}
 }
 
@@ -415,6 +424,7 @@ namespace LLError
 		static void reset();
 		static Settings* saveAndReset();
 		static void restore(Settings*);
+		static void clean();
 		
 	private:
 		Settings()
@@ -446,6 +456,15 @@ namespace LLError
 		}
 		return *p;
 	}
+
+	void Settings::clean()
+	{
+		Globals::get().invalidateCallSites();
+
+		Settings*& p = getPtr();
+		delete p;
+		p = NULL;
+	}
 	
 	void Settings::reset()
 	{
@@ -480,10 +499,7 @@ namespace LLError
 		static Settings* currentSettings = NULL;
 		return currentSettings;
 	}
-}
 
-namespace LLError
-{
 	CallSite::CallSite(ELevel level,
 					const char* file,
 					int line,
@@ -721,11 +737,7 @@ namespace LLError
 			setLevels(s.tagLevelMap,		entry["tags"],		level);
 		}
 	}
-}
-
 
-namespace LLError
-{
 	Recorder::~Recorder()
 		{ }
 
@@ -756,18 +768,26 @@ namespace LLError
 			std::remove(s.recorders.begin(), s.recorders.end(), recorder),
 			s.recorders.end());
 	}
-}
 
-namespace LLError
-{
+	void deleteRecorder(LLError::Settings& settings)
+	{
+		removeRecorder(settings.fileRecorder);
+		delete settings.fileRecorder;
+		settings.fileRecorder = NULL;
+		settings.fileRecorderFileName.clear();
+	}
+
+	void clean()
+	{
+		deleteRecorder(LLError::Settings::get());
+		LLError::Settings::clean();
+	}
+
 	void logToFile(const std::string& file_name)
 	{
 		LLError::Settings& s = LLError::Settings::get();
 
-		removeRecorder(s.fileRecorder);
-		delete s.fileRecorder;
-		s.fileRecorder = NULL;
-		s.fileRecorderFileName.clear();
+		deleteRecorder(s);
 		
 		if (file_name.empty())
 		{
@@ -839,8 +859,6 @@ namespace
 			}
 		}
 	}
-}
-
 
 /*
 Recorder formats:
@@ -870,7 +888,6 @@ You get:
 	
 */
 
-namespace {
 	bool checkLevelMap(const LevelMap& map, const std::string& key,
 						LLError::ELevel& level)
 	{
@@ -1127,13 +1144,7 @@ namespace LLError
 			s.crashFunction(message);
 		}
 	}
-}
-
-
-
 
-namespace LLError
-{
 	Settings* saveAndResetSettings()
 	{
 		return Settings::saveAndReset();
@@ -1226,10 +1237,7 @@ namespace LLError
 
 		return chars ? time_str : "time error";
 	}
-}
-
-namespace LLError
-{     
+     
 	char** LLCallStacks::sBuffer = NULL ;
 	S32    LLCallStacks::sIndex  = 0 ;
 
diff --git a/indra/llcrashlogger/llcrashlogger.cpp b/indra/llcrashlogger/llcrashlogger.cpp
index fb2d43e3b0d..aa66ceb4ecc 100755
--- a/indra/llcrashlogger/llcrashlogger.cpp
+++ b/indra/llcrashlogger/llcrashlogger.cpp
@@ -44,7 +44,7 @@
 #include "llsdserialize.h"
 #include "llproxy.h"
 
-LLPumpIO* gServicePump;
+LLPumpIO* gServicePump = NULL;
 BOOL gBreak = false;
 BOOL gSent = false;
 
@@ -80,7 +80,8 @@ LLCrashLogger::LLCrashLogger() :
 
 LLCrashLogger::~LLCrashLogger()
 {
-
+	delete gServicePump;
+	gServicePump = NULL;
 }
 
 // TRIM_SIZE must remain larger than LINE_SEARCH_SIZE.
diff --git a/indra/llmessage/llhttpsender.cpp b/indra/llmessage/llhttpsender.cpp
index c48cbc42a62..d0bd343db6d 100755
--- a/indra/llmessage/llhttpsender.cpp
+++ b/indra/llmessage/llhttpsender.cpp
@@ -38,7 +38,7 @@ namespace
 {
 	typedef std::map<LLHost, LLHTTPSender*> SenderMap;
 	static SenderMap senderMap;
-	static LLHTTPSender* defaultSender = new LLHTTPSender();
+	static LLPointer<LLHTTPSender> defaultSender(new LLHTTPSender());
 }
 
 //virtual 
@@ -90,6 +90,5 @@ void LLHTTPSender::clearSender(const LLHost& host)
 //static 
 void LLHTTPSender::setDefaultSender(LLHTTPSender* sender)
 {
-	delete defaultSender;
 	defaultSender = sender;
 }
diff --git a/indra/llmessage/llhttpsender.h b/indra/llmessage/llhttpsender.h
index 88920db24d4..ff8fa2f95b1 100755
--- a/indra/llmessage/llhttpsender.h
+++ b/indra/llmessage/llhttpsender.h
@@ -32,7 +32,7 @@
 class LLHost;
 class LLSD;
 
-class LLHTTPSender
+class LLHTTPSender : public LLThreadSafeRefCount
 {
  public:
 
diff --git a/indra/llui/llpanel.h b/indra/llui/llpanel.h
index e63b41f97c5..17b9b91ba79 100755
--- a/indra/llui/llpanel.h
+++ b/indra/llui/llpanel.h
@@ -330,17 +330,16 @@ class LLRegisterPanelClass
 
 // local static instance for registering a particular panel class
 template<typename T>
-class LLRegisterPanelClassWrapper
-:	public LLRegisterPanelClass
+	class LLPanelInjector
 {
 public:
-	// reigister with either the provided builder, or the generic templated builder
-	LLRegisterPanelClassWrapper(const std::string& tag);
+	// register with either the provided builder, or the generic templated builder
+	LLPanelInjector(const std::string& tag);
 };
 
 
 template<typename T>
-LLRegisterPanelClassWrapper<T>::LLRegisterPanelClassWrapper(const std::string& tag) 
+	LLPanelInjector<T>::LLPanelInjector(const std::string& tag) 
 {
 	LLRegisterPanelClass::instance().addPanelClass(tag,&LLRegisterPanelClass::defaultPanelClassBuilder<T>);
 }
diff --git a/indra/newview/llappviewerwin32.cpp b/indra/newview/llappviewerwin32.cpp
index 80a80f42989..2764025d75d 100755
--- a/indra/newview/llappviewerwin32.cpp
+++ b/indra/newview/llappviewerwin32.cpp
@@ -200,14 +200,6 @@ int APIENTRY WINMAIN(HINSTANCE hInstance,
                      LPSTR     lpCmdLine,
                      int       nCmdShow)
 {
-#ifdef INCLUDE_VLD
-	// only works for debug builds (hard coded into vld.h)
-	#ifdef _DEBUG
-		// start with Visual Leak Detector turned off
-		VLDGlobalDisable();
-	#endif // _DEBUG
-#endif // INCLUDE_VLD
-
 	const S32 MAX_HEAPS = 255;
 	DWORD heap_enable_lfh_error[MAX_HEAPS];
 	S32 num_heaps = 0;
diff --git a/indra/newview/llcofwearables.cpp b/indra/newview/llcofwearables.cpp
index e86d6930e89..e200e0ee9ed 100755
--- a/indra/newview/llcofwearables.cpp
+++ b/indra/newview/llcofwearables.cpp
@@ -43,7 +43,7 @@
 #include "llpaneloutfitedit.h"
 #include "lltrans.h"
 
-static LLRegisterPanelClassWrapper<LLCOFWearables> t_cof_wearables("cof_wearables");
+static LLPanelInjector<LLCOFWearables> t_cof_wearables("cof_wearables");
 
 const LLSD REARRANGE = LLSD().with("rearrange", LLSD());
 
diff --git a/indra/newview/llfloatercamera.cpp b/indra/newview/llfloatercamera.cpp
index c85d048c5a9..d0939b3eee5 100755
--- a/indra/newview/llfloatercamera.cpp
+++ b/indra/newview/llfloatercamera.cpp
@@ -151,7 +151,7 @@ void LLPanelCameraItem::setValue(const LLSD& value)
 	getChildView("selected_picture")->setVisible( value["selected"]);
 }
 
-static LLRegisterPanelClassWrapper<LLPanelCameraZoom> t_camera_zoom_panel("camera_zoom_panel");
+static LLPanelInjector<LLPanelCameraZoom> t_camera_zoom_panel("camera_zoom_panel");
 
 //-------------------------------------------------------------------------------
 // LLPanelCameraZoom
diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp
index c339ee3bebc..b50a2e6f853 100755
--- a/indra/newview/llfloaterpreference.cpp
+++ b/indra/newview/llfloaterpreference.cpp
@@ -1823,7 +1823,7 @@ class LLPanelPreference::Updater : public LLEventTimer
 	callback_t mCallback;
 };
 //----------------------------------------------------------------------------
-static LLRegisterPanelClassWrapper<LLPanelPreference> t_places("panel_preference");
+static LLPanelInjector<LLPanelPreference> t_places("panel_preference");
 LLPanelPreference::LLPanelPreference()
 : LLPanel(),
   mBandWidthUpdater(NULL)
@@ -2063,8 +2063,8 @@ class LLPanelPreferencePrivacy : public LLPanelPreference
 	std::list<std::string> mAccountIndependentSettings;
 };
 
-static LLRegisterPanelClassWrapper<LLPanelPreferenceGraphics> t_pref_graph("panel_preference_graphics");
-static LLRegisterPanelClassWrapper<LLPanelPreferencePrivacy> t_pref_privacy("panel_preference_privacy");
+static LLPanelInjector<LLPanelPreferenceGraphics> t_pref_graph("panel_preference_graphics");
+static LLPanelInjector<LLPanelPreferencePrivacy> t_pref_privacy("panel_preference_privacy");
 
 BOOL LLPanelPreferenceGraphics::postBuild()
 {
diff --git a/indra/newview/llfloatersocial.cpp b/indra/newview/llfloatersocial.cpp
index 2a74c8e3eac..9490769d8ca 100644
--- a/indra/newview/llfloatersocial.cpp
+++ b/indra/newview/llfloatersocial.cpp
@@ -47,10 +47,10 @@
 #include "llviewercontrol.h"
 #include "llviewermedia.h"
 
-static LLRegisterPanelClassWrapper<LLSocialStatusPanel> t_panel_status("llsocialstatuspanel");
-static LLRegisterPanelClassWrapper<LLSocialPhotoPanel> t_panel_photo("llsocialphotopanel");
-static LLRegisterPanelClassWrapper<LLSocialCheckinPanel> t_panel_checkin("llsocialcheckinpanel");
-static LLRegisterPanelClassWrapper<LLSocialAccountPanel> t_panel_account("llsocialaccountpanel");
+static LLPanelInjector<LLSocialStatusPanel> t_panel_status("llsocialstatuspanel");
+static LLPanelInjector<LLSocialPhotoPanel> t_panel_photo("llsocialphotopanel");
+static LLPanelInjector<LLSocialCheckinPanel> t_panel_checkin("llsocialcheckinpanel");
+static LLPanelInjector<LLSocialAccountPanel> t_panel_account("llsocialaccountpanel");
 
 const S32 MAX_POSTCARD_DATASIZE = 1024 * 1024; // one megabyte
 const std::string DEFAULT_CHECKIN_LOCATION_URL = "http://maps.secondlife.com/";
diff --git a/indra/newview/lloutfitslist.cpp b/indra/newview/lloutfitslist.cpp
index c15b6bd0d35..ff8bfafb791 100755
--- a/indra/newview/lloutfitslist.cpp
+++ b/indra/newview/lloutfitslist.cpp
@@ -343,7 +343,7 @@ class LLOutfitContextMenu : public LLListContextMenu
 
 //////////////////////////////////////////////////////////////////////////
 
-static LLRegisterPanelClassWrapper<LLOutfitsList> t_outfits_list("outfits_list");
+static LLPanelInjector<LLOutfitsList> t_outfits_list("outfits_list");
 
 LLOutfitsList::LLOutfitsList()
 	:	LLPanelAppearanceTab()
diff --git a/indra/newview/llpanelblockedlist.cpp b/indra/newview/llpanelblockedlist.cpp
index 115114bb53b..9665314e753 100755
--- a/indra/newview/llpanelblockedlist.cpp
+++ b/indra/newview/llpanelblockedlist.cpp
@@ -48,7 +48,7 @@
 #include "llsidetraypanelcontainer.h"
 #include "llviewercontrol.h"
 
-static LLRegisterPanelClassWrapper<LLPanelBlockedList> t_panel_blocked_list("panel_block_list_sidetray");
+static LLPanelInjector<LLPanelBlockedList> t_panel_blocked_list("panel_block_list_sidetray");
 
 //
 // Constants
diff --git a/indra/newview/llpaneleditwearable.cpp b/indra/newview/llpaneleditwearable.cpp
index e71dba5caee..0621cc8fad1 100755
--- a/indra/newview/llpaneleditwearable.cpp
+++ b/indra/newview/llpaneleditwearable.cpp
@@ -62,7 +62,7 @@
 #include "llappearancemgr.h"
 
 // register panel with appropriate XML
-static LLRegisterPanelClassWrapper<LLPanelEditWearable> t_edit_wearable("panel_edit_wearable");
+static LLPanelInjector<LLPanelEditWearable> t_edit_wearable("panel_edit_wearable");
 
 // subparts of the UI for focus, camera position, etc.
 enum ESubpart {
diff --git a/indra/newview/llpanelgroup.cpp b/indra/newview/llpanelgroup.cpp
index a0ca82da46a..c872a15af7f 100755
--- a/indra/newview/llpanelgroup.cpp
+++ b/indra/newview/llpanelgroup.cpp
@@ -56,7 +56,7 @@
 
 #include "lltrans.h"
 
-static LLRegisterPanelClassWrapper<LLPanelGroup> t_panel_group("panel_group_info_sidetray");
+static LLPanelInjector<LLPanelGroup> t_panel_group("panel_group_info_sidetray");
 
 
 
diff --git a/indra/newview/llpanelgroupgeneral.cpp b/indra/newview/llpanelgroupgeneral.cpp
index 68835ec5b80..eaf33c71086 100755
--- a/indra/newview/llpanelgroupgeneral.cpp
+++ b/indra/newview/llpanelgroupgeneral.cpp
@@ -53,7 +53,7 @@
 #include "lltrans.h"
 #include "llviewerwindow.h"
 
-static LLRegisterPanelClassWrapper<LLPanelGroupGeneral> t_panel_group_general("panel_group_general");
+static LLPanelInjector<LLPanelGroupGeneral> t_panel_group_general("panel_group_general");
 
 // consts
 const S32 MATURE_CONTENT = 1;
diff --git a/indra/newview/llpanelgrouplandmoney.cpp b/indra/newview/llpanelgrouplandmoney.cpp
index c927aeacb30..17707557bb2 100755
--- a/indra/newview/llpanelgrouplandmoney.cpp
+++ b/indra/newview/llpanelgrouplandmoney.cpp
@@ -55,7 +55,7 @@
 #include "llfloaterworldmap.h"
 #include "llviewermessage.h"
 
-static LLRegisterPanelClassWrapper<LLPanelGroupLandMoney> t_panel_group_money("panel_group_land_money");
+static LLPanelInjector<LLPanelGroupLandMoney> t_panel_group_money("panel_group_land_money");
 
 
 
diff --git a/indra/newview/llpanelgroupnotices.cpp b/indra/newview/llpanelgroupnotices.cpp
index 522ba5afae4..0dfb8fef53f 100755
--- a/indra/newview/llpanelgroupnotices.cpp
+++ b/indra/newview/llpanelgroupnotices.cpp
@@ -57,7 +57,7 @@
 #include "llnotificationsutil.h"
 #include "llgiveinventory.h"
 
-static LLRegisterPanelClassWrapper<LLPanelGroupNotices> t_panel_group_notices("panel_group_notices");
+static LLPanelInjector<LLPanelGroupNotices> t_panel_group_notices("panel_group_notices");
 
 
 /////////////////////////
diff --git a/indra/newview/llpanelgrouproles.cpp b/indra/newview/llpanelgrouproles.cpp
index b89e7b8b73b..c30c932c415 100755
--- a/indra/newview/llpanelgrouproles.cpp
+++ b/indra/newview/llpanelgrouproles.cpp
@@ -55,7 +55,7 @@
 
 #include "roles_constants.h"
 
-static LLRegisterPanelClassWrapper<LLPanelGroupRoles> t_panel_group_roles("panel_group_roles");
+static LLPanelInjector<LLPanelGroupRoles> t_panel_group_roles("panel_group_roles");
 
 bool agentCanRemoveFromRole(const LLUUID& group_id,
 							const LLUUID& role_id)
@@ -733,7 +733,7 @@ void LLPanelGroupSubTab::setFooterEnabled(BOOL enable)
 ////////////////////////////
 
 
-static LLRegisterPanelClassWrapper<LLPanelGroupMembersSubTab> t_panel_group_members_subtab("panel_group_members_subtab");
+static LLPanelInjector<LLPanelGroupMembersSubTab> t_panel_group_members_subtab("panel_group_members_subtab");
 
 LLPanelGroupMembersSubTab::LLPanelGroupMembersSubTab()
 : 	LLPanelGroupSubTab(),
@@ -1755,7 +1755,7 @@ void LLPanelGroupMembersSubTab::updateMembers()
 // LLPanelGroupRolesSubTab
 ////////////////////////////
 
-static LLRegisterPanelClassWrapper<LLPanelGroupRolesSubTab> t_panel_group_roles_subtab("panel_group_roles_subtab");
+static LLPanelInjector<LLPanelGroupRolesSubTab> t_panel_group_roles_subtab("panel_group_roles_subtab");
 
 LLPanelGroupRolesSubTab::LLPanelGroupRolesSubTab()
   : LLPanelGroupSubTab(),
@@ -2469,7 +2469,7 @@ void LLPanelGroupRolesSubTab::saveRoleChanges(bool select_saved_role)
 // LLPanelGroupActionsSubTab
 ////////////////////////////
 
-static LLRegisterPanelClassWrapper<LLPanelGroupActionsSubTab> t_panel_group_actions_subtab("panel_group_actions_subtab");
+static LLPanelInjector<LLPanelGroupActionsSubTab> t_panel_group_actions_subtab("panel_group_actions_subtab");
 
 
 LLPanelGroupActionsSubTab::LLPanelGroupActionsSubTab()
diff --git a/indra/newview/llpanelhome.cpp b/indra/newview/llpanelhome.cpp
index b03bab31272..ab0ccffae49 100755
--- a/indra/newview/llpanelhome.cpp
+++ b/indra/newview/llpanelhome.cpp
@@ -31,7 +31,7 @@
 #include "llmediactrl.h"
 #include "llviewerhome.h"
 
-static LLRegisterPanelClassWrapper<LLPanelHome> t_home("panel_sidetray_home");
+static LLPanelInjector<LLPanelHome> t_home("panel_sidetray_home");
 
 LLPanelHome::LLPanelHome() :
 	LLPanel(),
diff --git a/indra/newview/llpanellandmarkinfo.cpp b/indra/newview/llpanellandmarkinfo.cpp
index 5c9b968ac90..934f8ed8c75 100755
--- a/indra/newview/llpanellandmarkinfo.cpp
+++ b/indra/newview/llpanellandmarkinfo.cpp
@@ -53,7 +53,7 @@ typedef std::pair<LLUUID, std::string> folder_pair_t;
 static bool cmp_folders(const folder_pair_t& left, const folder_pair_t& right);
 static void collectLandmarkFolders(LLInventoryModel::cat_array_t& cats);
 
-static LLRegisterPanelClassWrapper<LLPanelLandmarkInfo> t_landmark_info("panel_landmark_info");
+static LLPanelInjector<LLPanelLandmarkInfo> t_landmark_info("panel_landmark_info");
 
 // Statics for textures filenames
 static std::string icon_pg;
diff --git a/indra/newview/llpanelmaininventory.cpp b/indra/newview/llpanelmaininventory.cpp
index bd173fadc73..68c22c12fd1 100755
--- a/indra/newview/llpanelmaininventory.cpp
+++ b/indra/newview/llpanelmaininventory.cpp
@@ -58,7 +58,7 @@
 
 const std::string FILTERS_FILENAME("filters.xml");
 
-static LLRegisterPanelClassWrapper<LLPanelMainInventory> t_inventory("panel_main_inventory");
+static LLPanelInjector<LLPanelMainInventory> t_inventory("panel_main_inventory");
 
 void on_file_loaded_for_save(BOOL success, 
 							 LLViewerFetchedTexture *src_vi,
diff --git a/indra/newview/llpanelmarketplaceinbox.cpp b/indra/newview/llpanelmarketplaceinbox.cpp
index dcecce6fe42..79e079f6bdf 100755
--- a/indra/newview/llpanelmarketplaceinbox.cpp
+++ b/indra/newview/llpanelmarketplaceinbox.cpp
@@ -38,7 +38,7 @@
 #include "llviewercontrol.h"
 
 
-static LLRegisterPanelClassWrapper<LLPanelMarketplaceInbox> t_panel_marketplace_inbox("panel_marketplace_inbox");
+static LLPanelInjector<LLPanelMarketplaceInbox> t_panel_marketplace_inbox("panel_marketplace_inbox");
 
 const LLPanelMarketplaceInbox::Params& LLPanelMarketplaceInbox::getDefaultParams() 
 { 
diff --git a/indra/newview/llpanelme.cpp b/indra/newview/llpanelme.cpp
index a9af56f750b..7a408e736f5 100755
--- a/indra/newview/llpanelme.cpp
+++ b/indra/newview/llpanelme.cpp
@@ -48,7 +48,7 @@
 #include "lltabcontainer.h"
 #include "lltexturectrl.h"
 
-static LLRegisterPanelClassWrapper<LLPanelMe> t_panel_me_profile("panel_me");
+static LLPanelInjector<LLPanelMe> t_panel_me_profile("panel_me");
 
 LLPanelMe::LLPanelMe(void) 
  : LLPanelProfile()
diff --git a/indra/newview/llpaneloutfitedit.cpp b/indra/newview/llpaneloutfitedit.cpp
index c09d4393c81..f75d76da94d 100755
--- a/indra/newview/llpaneloutfitedit.cpp
+++ b/indra/newview/llpaneloutfitedit.cpp
@@ -74,7 +74,7 @@
 #include "llwearabletype.h"
 #include "llweb.h"
 
-static LLRegisterPanelClassWrapper<LLPanelOutfitEdit> t_outfit_edit("panel_outfit_edit");
+static LLPanelInjector<LLPanelOutfitEdit> t_outfit_edit("panel_outfit_edit");
 
 const U64 WEARABLE_MASK = (1LL << LLInventoryType::IT_WEARABLE);
 const U64 ATTACHMENT_MASK = (1LL << LLInventoryType::IT_ATTACHMENT) | (1LL << LLInventoryType::IT_OBJECT);
diff --git a/indra/newview/llpaneloutfitsinventory.cpp b/indra/newview/llpaneloutfitsinventory.cpp
index f90236f6f28..e0132d20fbf 100755
--- a/indra/newview/llpaneloutfitsinventory.cpp
+++ b/indra/newview/llpaneloutfitsinventory.cpp
@@ -46,7 +46,7 @@
 static const std::string OUTFITS_TAB_NAME = "outfitslist_tab";
 static const std::string COF_TAB_NAME = "cof_tab";
 
-static LLRegisterPanelClassWrapper<LLPanelOutfitsInventory> t_inventory("panel_outfits_inventory");
+static LLPanelInjector<LLPanelOutfitsInventory> t_inventory("panel_outfits_inventory");
 
 LLPanelOutfitsInventory::LLPanelOutfitsInventory() :
 	mMyOutfitsPanel(NULL),
diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp
index f551fc96eed..f5542ee7a6c 100755
--- a/indra/newview/llpanelpeople.cpp
+++ b/indra/newview/llpanelpeople.cpp
@@ -216,7 +216,7 @@ static const LLAvatarItemStatusComparator STATUS_COMPARATOR;
 static LLAvatarItemDistanceComparator DISTANCE_COMPARATOR;
 static const LLAvatarItemRecentSpeakerComparator RECENT_SPEAKER_COMPARATOR;
 
-static LLRegisterPanelClassWrapper<LLPanelPeople> t_people("panel_people");
+static LLPanelInjector<LLPanelPeople> t_people("panel_people");
 
 //=============================================================================
 
diff --git a/indra/newview/llpanelpicks.cpp b/indra/newview/llpanelpicks.cpp
index cfbc8f1a94d..f0617266dbd 100755
--- a/indra/newview/llpanelpicks.cpp
+++ b/indra/newview/llpanelpicks.cpp
@@ -69,7 +69,7 @@ static const std::string CLASSIFIED_ID("classified_id");
 static const std::string CLASSIFIED_NAME("classified_name");
 
 
-static LLRegisterPanelClassWrapper<LLPanelPicks> t_panel_picks("panel_picks");
+static LLPanelInjector<LLPanelPicks> t_panel_picks("panel_picks");
 
 
 class LLPickHandler : public LLCommandHandler,
diff --git a/indra/newview/llpanelplaceprofile.cpp b/indra/newview/llpanelplaceprofile.cpp
index 5d9971c16c1..14b5d9af47c 100755
--- a/indra/newview/llpanelplaceprofile.cpp
+++ b/indra/newview/llpanelplaceprofile.cpp
@@ -53,7 +53,7 @@
 #include "llviewerparcelmgr.h"
 #include "llviewerregion.h"
 
-static LLRegisterPanelClassWrapper<LLPanelPlaceProfile> t_place_profile("panel_place_profile");
+static LLPanelInjector<LLPanelPlaceProfile> t_place_profile("panel_place_profile");
 
 // Statics for textures filenames
 static std::string icon_pg;
diff --git a/indra/newview/llpanelplaces.cpp b/indra/newview/llpanelplaces.cpp
index 8bb3ace2d9f..499b9ab62e1 100755
--- a/indra/newview/llpanelplaces.cpp
+++ b/indra/newview/llpanelplaces.cpp
@@ -229,7 +229,7 @@ class LLPlacesRemoteParcelInfoObserver : public LLRemoteParcelInfoObserver
 };
 
 
-static LLRegisterPanelClassWrapper<LLPanelPlaces> t_places("panel_places");
+static LLPanelInjector<LLPanelPlaces> t_places("panel_places");
 
 LLPanelPlaces::LLPanelPlaces()
 	:	LLPanel(),
diff --git a/indra/newview/llpanelsnapshotinventory.cpp b/indra/newview/llpanelsnapshotinventory.cpp
index 381c11348d5..47e46a968f8 100755
--- a/indra/newview/llpanelsnapshotinventory.cpp
+++ b/indra/newview/llpanelsnapshotinventory.cpp
@@ -60,7 +60,7 @@ class LLPanelSnapshotInventory
 	void onSend();
 };
 
-static LLRegisterPanelClassWrapper<LLPanelSnapshotInventory> panel_class("llpanelsnapshotinventory");
+static LLPanelInjector<LLPanelSnapshotInventory> panel_class("llpanelsnapshotinventory");
 
 LLPanelSnapshotInventory::LLPanelSnapshotInventory()
 {
diff --git a/indra/newview/llpanelsnapshotlocal.cpp b/indra/newview/llpanelsnapshotlocal.cpp
index d153ff598d0..43e38b95e25 100755
--- a/indra/newview/llpanelsnapshotlocal.cpp
+++ b/indra/newview/llpanelsnapshotlocal.cpp
@@ -63,7 +63,7 @@ class LLPanelSnapshotLocal
 	void onSaveFlyoutCommit(LLUICtrl* ctrl);
 };
 
-static LLRegisterPanelClassWrapper<LLPanelSnapshotLocal> panel_class("llpanelsnapshotlocal");
+static LLPanelInjector<LLPanelSnapshotLocal> panel_class("llpanelsnapshotlocal");
 
 LLPanelSnapshotLocal::LLPanelSnapshotLocal()
 {
diff --git a/indra/newview/llpanelsnapshotoptions.cpp b/indra/newview/llpanelsnapshotoptions.cpp
index 554fabe5b3d..455c1c9e5fa 100755
--- a/indra/newview/llpanelsnapshotoptions.cpp
+++ b/indra/newview/llpanelsnapshotoptions.cpp
@@ -56,7 +56,7 @@ class LLPanelSnapshotOptions
 	void onSaveToComputer();
 };
 
-static LLRegisterPanelClassWrapper<LLPanelSnapshotOptions> panel_class("llpanelsnapshotoptions");
+static LLPanelInjector<LLPanelSnapshotOptions> panel_class("llpanelsnapshotoptions");
 
 LLPanelSnapshotOptions::LLPanelSnapshotOptions()
 {
diff --git a/indra/newview/llpanelsnapshotpostcard.cpp b/indra/newview/llpanelsnapshotpostcard.cpp
index f2bb8f530ba..aa109e9a512 100755
--- a/indra/newview/llpanelsnapshotpostcard.cpp
+++ b/indra/newview/llpanelsnapshotpostcard.cpp
@@ -79,7 +79,7 @@ class LLPanelSnapshotPostcard
 	std::string mAgentEmail;
 };
 
-static LLRegisterPanelClassWrapper<LLPanelSnapshotPostcard> panel_class("llpanelsnapshotpostcard");
+static LLPanelInjector<LLPanelSnapshotPostcard> panel_class("llpanelsnapshotpostcard");
 
 LLPanelSnapshotPostcard::LLPanelSnapshotPostcard()
 :	mHasFirstMsgFocus(false)
diff --git a/indra/newview/llpanelsnapshotprofile.cpp b/indra/newview/llpanelsnapshotprofile.cpp
index a7063183692..8949eb73eba 100755
--- a/indra/newview/llpanelsnapshotprofile.cpp
+++ b/indra/newview/llpanelsnapshotprofile.cpp
@@ -64,7 +64,7 @@ class LLPanelSnapshotProfile
 	void onSend();
 };
 
-static LLRegisterPanelClassWrapper<LLPanelSnapshotProfile> panel_class("llpanelsnapshotprofile");
+static LLPanelInjector<LLPanelSnapshotProfile> panel_class("llpanelsnapshotprofile");
 
 LLPanelSnapshotProfile::LLPanelSnapshotProfile()
 {
diff --git a/indra/newview/llpanelvoicedevicesettings.cpp b/indra/newview/llpanelvoicedevicesettings.cpp
index 6be2ea6481c..6f0a1624a79 100755
--- a/indra/newview/llpanelvoicedevicesettings.cpp
+++ b/indra/newview/llpanelvoicedevicesettings.cpp
@@ -40,7 +40,7 @@
 #include "lluictrlfactory.h"
 
 
-static LLRegisterPanelClassWrapper<LLPanelVoiceDeviceSettings> t_panel_group_general("panel_voice_device_settings");
+static LLPanelInjector<LLPanelVoiceDeviceSettings> t_panel_group_general("panel_voice_device_settings");
 static const std::string DEFAULT_DEVICE("Default");
 
 
diff --git a/indra/newview/llpanelvoiceeffect.cpp b/indra/newview/llpanelvoiceeffect.cpp
index 5fec6d967d4..7da553801a1 100755
--- a/indra/newview/llpanelvoiceeffect.cpp
+++ b/indra/newview/llpanelvoiceeffect.cpp
@@ -36,7 +36,7 @@
 #include "lltransientfloatermgr.h"
 #include "llvoiceclient.h"
 
-static LLRegisterPanelClassWrapper<LLPanelVoiceEffect> t_panel_voice_effect("panel_voice_effect");
+static LLPanelInjector<LLPanelVoiceEffect> t_panel_voice_effect("panel_voice_effect");
 
 LLPanelVoiceEffect::LLPanelVoiceEffect()
 	: mVoiceEffectCombo(NULL)
diff --git a/indra/newview/llpanelwearing.cpp b/indra/newview/llpanelwearing.cpp
index aa3ed22bee8..edb624e3aad 100755
--- a/indra/newview/llpanelwearing.cpp
+++ b/indra/newview/llpanelwearing.cpp
@@ -151,7 +151,7 @@ class LLWearingContextMenu : public LLListContextMenu
 
 std::string LLPanelAppearanceTab::sFilterSubString = LLStringUtil::null;
 
-static LLRegisterPanelClassWrapper<LLPanelWearing> t_panel_wearing("panel_wearing");
+static LLPanelInjector<LLPanelWearing> t_panel_wearing("panel_wearing");
 
 LLPanelWearing::LLPanelWearing()
 	:	LLPanelAppearanceTab()
diff --git a/indra/newview/llpopupview.cpp b/indra/newview/llpopupview.cpp
index 08829c11840..153f0930c27 100755
--- a/indra/newview/llpopupview.cpp
+++ b/indra/newview/llpopupview.cpp
@@ -27,7 +27,7 @@
 
 #include "llpopupview.h"
 
-static LLRegisterPanelClassWrapper<LLPopupView> r("popup_holder");
+static LLPanelInjector<LLPopupView> r("popup_holder");
 
 bool view_visible_and_enabled(LLView* viewp)
 {
diff --git a/indra/newview/llprogressview.cpp b/indra/newview/llprogressview.cpp
index 989f0b0e605..1257ee7f949 100755
--- a/indra/newview/llprogressview.cpp
+++ b/indra/newview/llprogressview.cpp
@@ -59,7 +59,7 @@ S32 gStartImageWidth = 1;
 S32 gStartImageHeight = 1;
 const F32 FADE_TO_WORLD_TIME = 1.0f;
 
-static LLRegisterPanelClassWrapper<LLProgressView> r("progress_view");
+static LLPanelInjector<LLProgressView> r("progress_view");
 
 // XUI: Translate
 LLProgressView::LLProgressView() 
diff --git a/indra/newview/llsidepanelappearance.cpp b/indra/newview/llsidepanelappearance.cpp
index df413ab849a..ec6a1d9bdc1 100755
--- a/indra/newview/llsidepanelappearance.cpp
+++ b/indra/newview/llsidepanelappearance.cpp
@@ -49,7 +49,7 @@
 #include "llvoavatarself.h"
 #include "llviewerwearable.h"
 
-static LLRegisterPanelClassWrapper<LLSidepanelAppearance> t_appearance("sidepanel_appearance");
+static LLPanelInjector<LLSidepanelAppearance> t_appearance("sidepanel_appearance");
 
 class LLCurrentlyWornFetchObserver : public LLInventoryFetchItemsObserver
 {
diff --git a/indra/newview/llsidepanelinventory.cpp b/indra/newview/llsidepanelinventory.cpp
index fe844ce5e4d..1ce691f696b 100755
--- a/indra/newview/llsidepanelinventory.cpp
+++ b/indra/newview/llsidepanelinventory.cpp
@@ -59,7 +59,7 @@
 #include "llviewernetwork.h"
 #include "llweb.h"
 
-static LLRegisterPanelClassWrapper<LLSidepanelInventory> t_inventory("sidepanel_inventory");
+static LLPanelInjector<LLSidepanelInventory> t_inventory("sidepanel_inventory");
 
 //
 // Constants
diff --git a/indra/newview/llsidepaneliteminfo.cpp b/indra/newview/llsidepaneliteminfo.cpp
index 92c2863ffdf..e52b2f25597 100755
--- a/indra/newview/llsidepaneliteminfo.cpp
+++ b/indra/newview/llsidepaneliteminfo.cpp
@@ -127,7 +127,7 @@ void LLObjectInventoryObserver::inventoryChanged(LLViewerObject* object,
 /// Class LLSidepanelItemInfo
 ///----------------------------------------------------------------------------
 
-static LLRegisterPanelClassWrapper<LLSidepanelItemInfo> t_item_info("sidepanel_item_info");
+static LLPanelInjector<LLSidepanelItemInfo> t_item_info("sidepanel_item_info");
 
 // Default constructor
 LLSidepanelItemInfo::LLSidepanelItemInfo(const LLPanel::Params& p)
diff --git a/indra/newview/llsidepaneltaskinfo.cpp b/indra/newview/llsidepaneltaskinfo.cpp
index 9be6d0c5f1a..44280989297 100755
--- a/indra/newview/llsidepaneltaskinfo.cpp
+++ b/indra/newview/llsidepaneltaskinfo.cpp
@@ -71,7 +71,7 @@
 
 LLSidepanelTaskInfo* LLSidepanelTaskInfo::sActivePanel = NULL;
 
-static LLRegisterPanelClassWrapper<LLSidepanelTaskInfo> t_task_info("sidepanel_task_info");
+static LLPanelInjector<LLSidepanelTaskInfo> t_task_info("sidepanel_task_info");
 
 // Default constructor
 LLSidepanelTaskInfo::LLSidepanelTaskInfo()
diff --git a/indra/newview/lltool.h b/indra/newview/lltool.h
index ecc435d8441..c5bad9d5327 100755
--- a/indra/newview/lltool.h
+++ b/indra/newview/lltool.h
@@ -39,7 +39,7 @@ class LLView;
 class LLPanel;
 
 class LLTool
-:	public LLMouseHandler
+:	public LLMouseHandler, public LLThreadSafeRefCount
 {
 public:
 	LLTool( const std::string& name, LLToolComposite* composite = NULL );
diff --git a/indra/newview/lltoolcomp.cpp b/indra/newview/lltoolcomp.cpp
index 5270c3d33ff..b75d6b3dcbd 100755
--- a/indra/newview/lltoolcomp.cpp
+++ b/indra/newview/lltoolcomp.cpp
@@ -61,7 +61,7 @@ extern LLControlGroup gSavedSettings;
 
 
 // we use this in various places instead of NULL
-static LLTool* sNullTool = new LLTool(std::string("null"), NULL); 
+static LLPointer<LLTool> sNullTool(new LLTool(std::string("null"), NULL)); 
 
 //-----------------------------------------------------------------------
 // LLToolComposite
-- 
GitLab