From 60d3a46ec645497e8023142df0b2a9c7a346cbaa Mon Sep 17 00:00:00 2001
From: Aimee Linden <aimee@lindenlab.com>
Date: Tue, 14 Sep 2010 13:16:46 +0100
Subject: [PATCH] STORM-121 FIXED Unify clean up of objects on voice client
 shutdown so that it happens consistently.

---
 indra/newview/llvoicevivox.cpp | 37 ++++++++++++++++++++--------------
 indra/newview/llvoicevivox.h   |  5 ++++-
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp
index 2e003dd2b8..e674fec053 100644
--- a/indra/newview/llvoicevivox.cpp
+++ b/indra/newview/llvoicevivox.cpp
@@ -386,7 +386,7 @@ LLVivoxVoiceClient::~LLVivoxVoiceClient()
 {
 }
 
-//----------------------------------------------
+//---------------------------------------------------
 
 void LLVivoxVoiceClient::init(LLPumpIO *pump)
 {
@@ -400,7 +400,8 @@ void LLVivoxVoiceClient::terminate()
 	{
 		logout();
 		connectorShutdown();
-		closeSocket();		// Need to do this now -- bad things happen if the destructor does it later.	
+		closeSocket();		// Need to do this now -- bad things happen if the destructor does it later.
+		cleanUp();
 	}
 	else
 	{
@@ -408,6 +409,18 @@ void LLVivoxVoiceClient::terminate()
 	}
 }
 
+//---------------------------------------------------
+
+void LLVivoxVoiceClient::cleanUp()
+{
+	deleteAllSessions();
+	deleteAllBuddies();
+	deleteAllVoiceFonts();
+	deleteVoiceFontTemplates();
+}
+
+//---------------------------------------------------
+
 const LLVoiceVersionInfo& LLVivoxVoiceClient::getVersion()
 {
 	return mVoiceVersion;
@@ -776,14 +789,10 @@ void LLVivoxVoiceClient::stateMachine()
 	{
 		//MARK: stateDisableCleanup
 		case stateDisableCleanup:
-			// Clean up and reset everything. 
+			// Clean up and reset everything.
 			closeSocket();
-			deleteAllSessions();
-			deleteAllBuddies();
-			deleteAllVoiceFonts();
-			deleteVoiceFontTemplates();
+			cleanUp();
 
-			mConnectorHandle.clear();
 			mAccountHandle.clear();
 			mAccountPassword.clear();
 			mVoiceAccountServerURI.clear();
@@ -1675,12 +1684,9 @@ void LLVivoxVoiceClient::stateMachine()
 		//MARK: stateLoggedOut
 		case stateLoggedOut:			// logout response received
 			
-			// Once we're logged out, all these things are invalid.
+			// Once we're logged out, these things are invalid.
 			mAccountHandle.clear();
-			deleteAllSessions();
-			deleteAllBuddies();
-			deleteAllVoiceFonts();
-			deleteVoiceFontTemplates();
+			cleanUp();
 
 			if(mVoiceEnabled && !mRelogRequested)
 			{
@@ -1778,6 +1784,8 @@ void LLVivoxVoiceClient::closeSocket(void)
 {
 	mSocket.reset();
 	mConnected = false;	
+	mConnectorHandle.clear();
+	mAccountHandle.clear();
 }
 
 void LLVivoxVoiceClient::loginSendMessage()
@@ -2370,8 +2378,7 @@ void LLVivoxVoiceClient::giveUp()
 {
 	// All has failed.  Clean up and stop trying.
 	closeSocket();
-	deleteAllSessions();
-	deleteAllBuddies();
+	cleanUp();
 	
 	setState(stateJail);
 }
diff --git a/indra/newview/llvoicevivox.h b/indra/newview/llvoicevivox.h
index d10a562616..08f2f75a39 100644
--- a/indra/newview/llvoicevivox.h
+++ b/indra/newview/llvoicevivox.h
@@ -668,7 +668,10 @@ protected:
 
 private:
 	LLVoiceVersionInfo mVoiceVersion;
-		
+
+	/// Clean up objects created during a voice session.
+	void cleanUp();
+
 	state mState;
 	bool mSessionTerminateRequested;
 	bool mRelogRequested;
-- 
GitLab