From 205503dd84479be4989e5f5567a1d187cc0e71eb Mon Sep 17 00:00:00 2001
From: Stinson Linden <stinson@lindenlab.com>
Date: Fri, 2 May 2014 23:04:06 +0100
Subject: [PATCH] MAINT-4009: Patching the memory leak occurring from the info
 icons that appear when hovering over a chat history item.

---
 indra/newview/llchathistory.cpp | 47 ++++++++++-----------------------
 indra/newview/llchathistory.h   |  7 ++---
 2 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp
index 05c4181714b..84b9ac756a1 100755
--- a/indra/newview/llchathistory.cpp
+++ b/indra/newview/llchathistory.cpp
@@ -107,6 +107,7 @@ class LLChatHistoryHeader: public LLPanel
 public:
 	LLChatHistoryHeader()
 	:	LLPanel(),
+		mInfoCtrl(NULL),
 		mPopupMenuHandleAvatar(),
 		mPopupMenuHandleObject(),
 		mAvatarID(),
@@ -129,9 +130,6 @@ class LLChatHistoryHeader: public LLPanel
 
 	~LLChatHistoryHeader()
 	{
-		// Detach the info button so that it doesn't get destroyed (EXT-8463).
-		hideInfoCtrl();
-
 		if (mAvatarNameCacheConnection.connected())
 		{
 			mAvatarNameCacheConnection.disconnect();
@@ -292,6 +290,11 @@ class LLChatHistoryHeader: public LLPanel
 		mUserNameTextBox = getChild<LLTextBox>("user_name");
 		mTimeBoxTextBox = getChild<LLTextBox>("time_box");
 
+		mInfoCtrl = LLUICtrlFactory::getInstance()->createFromFile<LLUICtrl>("inspector_info_ctrl.xml", this, LLPanel::child_registry_t::instance());
+		llassert(mInfoCtrl != NULL);
+		mInfoCtrl->setCommitCallback(boost::bind(&LLChatHistoryHeader::onClickInfoCtrl, mInfoCtrl));
+		mInfoCtrl->setVisible(FALSE);
+
 		return LLPanel::postBuild();
 	}
 
@@ -589,39 +592,19 @@ class LLChatHistoryHeader: public LLPanel
 
 	void showInfoCtrl()
 	{
-		if (mAvatarID.isNull() || mFrom.empty() || CHAT_SOURCE_SYSTEM == mSourceType) return;
-				
-		if (!sInfoCtrl)
-		{
-			// *TODO: Delete the button at exit.
-			sInfoCtrl = LLUICtrlFactory::createFromFile<LLUICtrl>("inspector_info_ctrl.xml", NULL, LLPanel::child_registry_t::instance());
-			if (sInfoCtrl)
-			{
-				sInfoCtrl->setCommitCallback(boost::bind(&LLChatHistoryHeader::onClickInfoCtrl, sInfoCtrl));
-			}
-		}
-
-		if (!sInfoCtrl)
+		const bool isVisible = !mAvatarID.isNull() && !mFrom.empty() && CHAT_SOURCE_SYSTEM != mSourceType;
+		if (isVisible)
 		{
-			llassert(sInfoCtrl != NULL);
-			return;
+			const LLRect sticky_rect = mUserNameTextBox->getRect();
+			S32 icon_x = llmin(sticky_rect.mLeft + mUserNameTextBox->getTextBoundingRect().getWidth() + 7, sticky_rect.mRight - 3);
+			mInfoCtrl->setOrigin(icon_x, sticky_rect.getCenterY() - mInfoCtrl->getRect().getHeight() / 2 ) ;
 		}
-
-		LLTextBox* name = getChild<LLTextBox>("user_name");
-		LLRect sticky_rect = name->getRect();
-		S32 icon_x = llmin(sticky_rect.mLeft + name->getTextBoundingRect().getWidth() + 7, sticky_rect.mRight - 3);
-		sInfoCtrl->setOrigin(icon_x, sticky_rect.getCenterY() - sInfoCtrl->getRect().getHeight() / 2 ) ;
-		addChild(sInfoCtrl);
+		mInfoCtrl->setVisible(isVisible);
 	}
 
 	void hideInfoCtrl()
 	{
-		if (!sInfoCtrl) return;
-
-		if (sInfoCtrl->getParent() == this)
-		{
-			removeChild(sInfoCtrl);
-		}
+		mInfoCtrl->setVisible(FALSE);
 	}
 
 private:
@@ -692,7 +675,7 @@ class LLChatHistoryHeader: public LLPanel
 	LLHandle<LLView>	mPopupMenuHandleAvatar;
 	LLHandle<LLView>	mPopupMenuHandleObject;
 
-	static LLUICtrl*	sInfoCtrl;
+	LLUICtrl*			mInfoCtrl;
 
 	LLUUID			    mAvatarID;
 	LLSD				mObjectData;
@@ -709,8 +692,6 @@ class LLChatHistoryHeader: public LLPanel
 	boost::signals2::connection mAvatarNameCacheConnection;
 };
 
-LLUICtrl* LLChatHistoryHeader::sInfoCtrl = NULL;
-
 LLChatHistory::LLChatHistory(const LLChatHistory::Params& p)
 :	LLUICtrl(p),
 	mMessageHeaderFilename(p.message_header),
diff --git a/indra/newview/llchathistory.h b/indra/newview/llchathistory.h
index bb6d4fb59ce..44736a04895 100755
--- a/indra/newview/llchathistory.h
+++ b/indra/newview/llchathistory.h
@@ -93,14 +93,15 @@ class LLChatHistory : public LLUICtrl
 		 * @return pointer to LLView separator object.
 		 */
 		LLView* getSeparator();
+
+		void onClickMoreText();
+
+	private:
 		/**
 		 * Builds a message header.
 		 * @return pointer to LLView header object.
 		 */
 		LLView* getHeader(const LLChat& chat,const LLStyle::Params& style_params, const LLSD& args);
-
-		void onClickMoreText();
-
 	public:
 		~LLChatHistory();
 		LLSD getValue() const;   
-- 
GitLab