From 38915f119c5bf3d85084b12939ad815f68fefad0 Mon Sep 17 00:00:00 2001
From: simon <none@none>
Date: Fri, 14 Feb 2014 14:57:08 -0800
Subject: [PATCH] More memory cleanup of containers after DeletePairedPointer()
 usage.

---
 indra/llcharacter/llpose.cpp        | 1 +
 indra/llcommon/llfasttimer.cpp      | 1 +
 indra/llcommon/llstl.h              | 1 +
 indra/llmessage/llcachename.cpp     | 1 +
 indra/llmessage/llhttpnode.cpp      | 4 ++--
 indra/llmessage/llmessagetemplate.h | 1 +
 indra/llrender/llfontfreetype.cpp   | 1 +
 indra/llui/llkeywords.cpp           | 1 +
 indra/llui/llscrolllistctrl.cpp     | 1 +
 indra/llvfs/llvfs.cpp               | 1 +
 indra/llwindow/lldxhardware.cpp     | 2 ++
 indra/newview/llcallingcard.cpp     | 1 +
 indra/newview/lllandmarklist.cpp    | 1 +
 indra/newview/llvograss.cpp         | 1 +
 indra/newview/llvotree.cpp          | 1 +
 15 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/indra/llcharacter/llpose.cpp b/indra/llcharacter/llpose.cpp
index 55e1b6e9eaa..b1a7ebb1596 100755
--- a/indra/llcharacter/llpose.cpp
+++ b/indra/llcharacter/llpose.cpp
@@ -461,6 +461,7 @@ LLPoseBlender::LLPoseBlender()
 LLPoseBlender::~LLPoseBlender()
 {
 	for_each(mJointStateBlenderPool.begin(), mJointStateBlenderPool.end(), DeletePairedPointer());
+	mJointStateBlenderPool.clear();
 }
 
 //-----------------------------------------------------------------------------
diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp
index 01b6e60d2b0..58db7d0d178 100755
--- a/indra/llcommon/llfasttimer.cpp
+++ b/indra/llcommon/llfasttimer.cpp
@@ -119,6 +119,7 @@ class NamedTimerFactory : public LLSingleton<NamedTimerFactory>
 	~NamedTimerFactory()
 	{
 		std::for_each(mTimers.begin(), mTimers.end(), DeletePairedPointer());
+		mTimers.clear();
 
 		delete mTimerRoot;
 	}
diff --git a/indra/llcommon/llstl.h b/indra/llcommon/llstl.h
index d3941e1bc92..0a39288f5a0 100755
--- a/indra/llcommon/llstl.h
+++ b/indra/llcommon/llstl.h
@@ -98,6 +98,7 @@ struct DeletePointerArray
 // The general form is:
 //
 //  std::for_each(somemap.begin(), somemap.end(), DeletePairedPointer());
+//  somemap.clear();		// Don't leave dangling pointers around
 
 struct DeletePairedPointer
 {
diff --git a/indra/llmessage/llcachename.cpp b/indra/llmessage/llcachename.cpp
index 4e22f62a112..13d779ff83c 100755
--- a/indra/llmessage/llcachename.cpp
+++ b/indra/llmessage/llcachename.cpp
@@ -278,6 +278,7 @@ LLCacheName::Impl::Impl(LLMessageSystem* msg)
 LLCacheName::Impl::~Impl()
 {
 	for_each(mCache.begin(), mCache.end(), DeletePairedPointer());
+	mCache.clear();
 	for_each(mReplyQueue.begin(), mReplyQueue.end(), DeletePointer());
 	mReplyQueue.clear();
 }
diff --git a/indra/llmessage/llhttpnode.cpp b/indra/llmessage/llhttpnode.cpp
index 5c2f73eccb8..f6ccb5bddab 100755
--- a/indra/llmessage/llhttpnode.cpp
+++ b/indra/llmessage/llhttpnode.cpp
@@ -76,8 +76,8 @@ LLHTTPNode::LLHTTPNode()
 // virtual
 LLHTTPNode::~LLHTTPNode()
 {
-	std::for_each(impl.mNamedChildren.begin(), impl.mNamedChildren.end(),
-		DeletePairedPointer());
+	std::for_each(impl.mNamedChildren.begin(), impl.mNamedChildren.end(), DeletePairedPointer());
+	impl.mNamedChildren.clear();
 
 	delete impl.mWildcardChild;
 	
diff --git a/indra/llmessage/llmessagetemplate.h b/indra/llmessage/llmessagetemplate.h
index ae8e0087c14..005a49cedf2 100755
--- a/indra/llmessage/llmessagetemplate.h
+++ b/indra/llmessage/llmessagetemplate.h
@@ -118,6 +118,7 @@ class LLMsgData
 	~LLMsgData()
 	{
 		for_each(mMemberBlocks.begin(), mMemberBlocks.end(), DeletePairedPointer());
+		mMemberBlocks.clear();
 	}
 
 	void addBlock(LLMsgBlkData *blockp)
diff --git a/indra/llrender/llfontfreetype.cpp b/indra/llrender/llfontfreetype.cpp
index 058bef43a56..84c782e9581 100755
--- a/indra/llrender/llfontfreetype.cpp
+++ b/indra/llrender/llfontfreetype.cpp
@@ -125,6 +125,7 @@ LLFontFreetype::~LLFontFreetype()
 
 	// Delete glyph info
 	std::for_each(mCharGlyphInfoMap.begin(), mCharGlyphInfoMap.end(), DeletePairedPointer());
+	mCharGlyphInfoMap.clear();
 
 	// mFontBitmapCachep will be cleaned up by LLPointer destructor.
 	// mFallbackFonts cleaned up by LLPointer destructor
diff --git a/indra/llui/llkeywords.cpp b/indra/llui/llkeywords.cpp
index ddf33cf6e08..39153977bf1 100755
--- a/indra/llui/llkeywords.cpp
+++ b/indra/llui/llkeywords.cpp
@@ -76,6 +76,7 @@ inline BOOL LLKeywordToken::isTail(const llwchar* s) const
 LLKeywords::~LLKeywords()
 {
 	std::for_each(mWordTokenMap.begin(), mWordTokenMap.end(), DeletePairedPointer());
+	mWordTokenMap.clear();
 	std::for_each(mLineTokenList.begin(), mLineTokenList.end(), DeletePointer());
 	mLineTokenList.clear();
 	std::for_each(mDelimiterTokenList.begin(), mDelimiterTokenList.end(), DeletePointer());
diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp
index 7cd49d5a540..d4bbea0f8ec 100755
--- a/indra/llui/llscrolllistctrl.cpp
+++ b/indra/llui/llscrolllistctrl.cpp
@@ -322,6 +322,7 @@ LLScrollListCtrl::~LLScrollListCtrl()
 	std::for_each(mItemList.begin(), mItemList.end(), DeletePointer());
 	mItemList.clear();
 	std::for_each(mColumns.begin(), mColumns.end(), DeletePairedPointer());
+	mColumns.clear();
 }
 
 
diff --git a/indra/llvfs/llvfs.cpp b/indra/llvfs/llvfs.cpp
index b31c6a99441..7b589f5b967 100755
--- a/indra/llvfs/llvfs.cpp
+++ b/indra/llvfs/llvfs.cpp
@@ -578,6 +578,7 @@ LLVFS::~LLVFS()
 	mFreeBlocksByLength.clear();
 
 	for_each(mFreeBlocksByLocation.begin(), mFreeBlocksByLocation.end(), DeletePairedPointer());
+	mFreeBlocksByLocation.clear();
     
 	unlockAndClose(mDataFP);
 	mDataFP = NULL;
diff --git a/indra/llwindow/lldxhardware.cpp b/indra/llwindow/lldxhardware.cpp
index 3579b5d42f0..b0f4bc55035 100755
--- a/indra/llwindow/lldxhardware.cpp
+++ b/indra/llwindow/lldxhardware.cpp
@@ -171,6 +171,7 @@ std::string LLDXDriverFile::dump()
 LLDXDevice::~LLDXDevice()
 {
 	for_each(mDriverFiles.begin(), mDriverFiles.end(), DeletePairedPointer());
+	mDriverFiles.clear();
 }
 
 std::string LLDXDevice::dump()
@@ -230,6 +231,7 @@ LLDXHardware::LLDXHardware()
 void LLDXHardware::cleanup()
 {
   // for_each(mDevices.begin(), mDevices.end(), DeletePairedPointer());
+  // mDevices.clear();
 }
 
 /*
diff --git a/indra/newview/llcallingcard.cpp b/indra/newview/llcallingcard.cpp
index 56817a51bae..91741c2a775 100755
--- a/indra/newview/llcallingcard.cpp
+++ b/indra/newview/llcallingcard.cpp
@@ -117,6 +117,7 @@ LLAvatarTracker::~LLAvatarTracker()
 	std::for_each(mObservers.begin(), mObservers.end(), DeletePointer());
 	mObservers.clear();
 	std::for_each(mBuddyInfo.begin(), mBuddyInfo.end(), DeletePairedPointer());
+	mBuddyInfo.clear();
 }
 
 void LLAvatarTracker::track(const LLUUID& avatar_id, const std::string& name)
diff --git a/indra/newview/lllandmarklist.cpp b/indra/newview/lllandmarklist.cpp
index dd402de394a..a92df8250eb 100755
--- a/indra/newview/lllandmarklist.cpp
+++ b/indra/newview/lllandmarklist.cpp
@@ -46,6 +46,7 @@ LLLandmarkList gLandmarkList;
 LLLandmarkList::~LLLandmarkList()
 {
 	std::for_each(mList.begin(), mList.end(), DeletePairedPointer());
+	mList.clear();
 }
 
 LLLandmark* LLLandmarkList::getAsset(const LLUUID& asset_uuid, loaded_callback_t cb)
diff --git a/indra/newview/llvograss.cpp b/indra/newview/llvograss.cpp
index 485b0dc8ad4..600b44d371e 100755
--- a/indra/newview/llvograss.cpp
+++ b/indra/newview/llvograss.cpp
@@ -241,6 +241,7 @@ void LLVOGrass::initClass()
 void LLVOGrass::cleanupClass()
 {
 	for_each(sSpeciesTable.begin(), sSpeciesTable.end(), DeletePairedPointer());
+	sSpeciesTable.clear();
 }
 
 U32 LLVOGrass::processUpdateMessage(LLMessageSystem *mesgsys,
diff --git a/indra/newview/llvotree.cpp b/indra/newview/llvotree.cpp
index 6a89100bf53..b82c4fe7698 100755
--- a/indra/newview/llvotree.cpp
+++ b/indra/newview/llvotree.cpp
@@ -269,6 +269,7 @@ void LLVOTree::initClass()
 void LLVOTree::cleanupClass()
 {
 	std::for_each(sSpeciesTable.begin(), sSpeciesTable.end(), DeletePairedPointer());
+	sSpeciesTable.clear();
 }
 
 U32 LLVOTree::processUpdateMessage(LLMessageSystem *mesgsys,
-- 
GitLab