From ae900209cdda0460a1a16080fbd2a56ca2dc7852 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Tue, 15 Oct 2019 23:15:02 -0400
Subject: [PATCH] Another potential crashfix in vobjlist

---
 indra/newview/llviewerobjectlist.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/indra/newview/llviewerobjectlist.cpp b/indra/newview/llviewerobjectlist.cpp
index 9c2a66dd61..710f383c30 100644
--- a/indra/newview/llviewerobjectlist.cpp
+++ b/indra/newview/llviewerobjectlist.cpp
@@ -1383,8 +1383,13 @@ BOOL LLViewerObjectList::killObject(LLViewerObject *objectp)
 
 		// When we're killing objects, all we do is mark them as dead.
 		// We clean up the dead objects later.
-
-		objectp->markDead(); // does the right thing if object already dead
+		{
+			// We are going to cleanup a lot of smart pointers to this object, they might be last,
+			// and object being NULLed while inside it's own function won't be pretty
+			// so create a pointer to make sure object will stay alive untill markDead() finishes
+			LLPointer<LLViewerObject> sp(objectp);
+			sp->markDead(); // does the right thing if object already dead
+		}
 		return TRUE;
 	}
 
-- 
GitLab