From ee20c271220bf445dbd13b0b18702f7eaad469f9 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Wed, 11 Nov 2020 04:04:13 -0500
Subject: [PATCH] Fix glview leak on shutdown in macos

---
 indra/llwindow/llwindowmacosx-objc.mm |  1 +
 indra/llwindow/llwindowmacosx.cpp     | 12 ++++++------
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm
index 0e77ca6457e..cbbbccdc5bd 100644
--- a/indra/llwindow/llwindowmacosx-objc.mm
+++ b/indra/llwindow/llwindowmacosx-objc.mm
@@ -357,6 +357,7 @@ void removeGLView(GLViewRef view)
 {
 	[(LLOpenGLView*)view clearGLContext];
 	[(LLOpenGLView*)view removeFromSuperview];
+	[(LLOpenGLView*)view release];
 }
 
 void setupInputWindow(NSWindowRef window, GLViewRef glview)
diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp
index f5e49633805..5f89bf92b08 100644
--- a/indra/llwindow/llwindowmacosx.cpp
+++ b/indra/llwindow/llwindowmacosx.cpp
@@ -696,12 +696,6 @@ void LLWindowMacOSX::destroyContext()
 		mPixelFormat = NULL;
 	}
 
-	// Clean up the GL context
-	if(mContext != NULL)
-	{
-		CGLDestroyContext(mContext);
-	}
-	
 	// Destroy our LLOpenGLView
 	if(mGLView != NULL)
 	{
@@ -709,6 +703,12 @@ void LLWindowMacOSX::destroyContext()
 		mGLView = NULL;
 	}
 	
+	// Clean up the GL context
+	if(mContext != NULL)
+	{
+		CGLDestroyContext(mContext);
+	}
+	
 	// Close the window
 	if(mWindow != NULL)
 	{
-- 
GitLab