From c0abbb6a648778f2acfaabd4e70763c0e31f7790 Mon Sep 17 00:00:00 2001
From: Steve Bennetts <steve@lindenlab.com>
Date: Mon, 26 Oct 2009 23:41:18 -0700
Subject: [PATCH] Fixed a crash on exit in gInventory destructor.

---
 indra/newview/llappviewer.cpp      |  4 +++-
 indra/newview/llinventorymodel.cpp | 11 +++++++++--
 indra/newview/llinventorymodel.h   |  4 +++-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 923a66ee8e3..840fa542bd6 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -1350,7 +1350,9 @@ bool LLAppViewer::cleanup()
 	// Destroy the UI
 	if( gViewerWindow)
 		gViewerWindow->shutdownViews();
-
+	
+	gInventory.cleanupInventory();
+	
 	// Clean up selection managers after UI is destroyed, as UI may be observing them.
 	// Clean up before GL is shut down because we might be holding on to objects with texture references
 	LLSelectMgr::cleanupGlobals();
diff --git a/indra/newview/llinventorymodel.cpp b/indra/newview/llinventorymodel.cpp
index d5a527773cc..e49be83fbc7 100644
--- a/indra/newview/llinventorymodel.cpp
+++ b/indra/newview/llinventorymodel.cpp
@@ -175,13 +175,20 @@ LLInventoryModel::LLInventoryModel()
 
 // Destroys the object
 LLInventoryModel::~LLInventoryModel()
+{
+	cleanupInventory();
+}
+
+void LLInventoryModel::cleanupInventory()
 {
 	empty();
 	for (observer_list_t::iterator iter = mObservers.begin();
-		 iter != mObservers.end(); ++iter)
+		 iter != mObservers.end(); )
 	{
-		delete *iter;
+		LLInventoryObserver* observer = *iter++;
+		delete observer;
 	}
+	mObservers.clear();
 }
 
 // This is a convenience function to check if one object has a parent
diff --git a/indra/newview/llinventorymodel.h b/indra/newview/llinventorymodel.h
index 7d4f3372e97..d51460b374c 100644
--- a/indra/newview/llinventorymodel.h
+++ b/indra/newview/llinventorymodel.h
@@ -112,7 +112,9 @@ class LLInventoryModel
 	// construction & destruction
 	LLInventoryModel();
 	~LLInventoryModel();
-
+	
+	void cleanupInventory();
+	
 	class fetchInventoryResponder : public LLHTTPClient::Responder
 	{
 	public:
-- 
GitLab