From cbdf791fb1634c3c42c1e24da4b99dfdc3251f26 Mon Sep 17 00:00:00 2001
From: ruslantproductengine <ruslantproductengine@lindenlab.com>
Date: Tue, 1 Dec 2015 19:57:38 +0200
Subject: [PATCH] MAINT-1109 Toggling graphics options causes viewer memory to
 increase, eventually causing the rendering pipeline to fall over and crashing
 the viewer

Te reason of memory leak - unloaded shaders.
Fixed.
---
 indra/llrender/llglslshader.cpp | 18 +++++++++++++-----
 indra/llrender/llglslshader.h   |  4 +++-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp
index 0f260674ed7..52b8de8365e 100755
--- a/indra/llrender/llglslshader.cpp
+++ b/indra/llrender/llglslshader.cpp
@@ -324,6 +324,14 @@ LLGLSLShader::~LLGLSLShader()
 }
 
 void LLGLSLShader::unload()
+{
+    mShaderFiles.clear();
+    mDefines.clear();
+
+    unloadInternal();
+}
+
+void LLGLSLShader::unloadInternal()
 {
     sInstances.erase(this);
 
@@ -331,8 +339,6 @@ void LLGLSLShader::unload()
     mAttribute.clear();
     mTexture.clear();
     mUniform.clear();
-    mShaderFiles.clear();
-    mDefines.clear();
 
     if (mProgramObject)
     {
@@ -354,13 +360,13 @@ void LLGLSLShader::unload()
 
         mProgramObject = 0;
     }
-    
+
     if (mTimerQuery)
     {
         glDeleteQueriesARB(1, &mTimerQuery);
         mTimerQuery = 0;
     }
-    
+
     if (mSamplesQuery)
     {
         glDeleteQueriesARB(1, &mSamplesQuery);
@@ -369,7 +375,7 @@ void LLGLSLShader::unload()
 
     //hack to make apple not complain
     glGetError();
-    
+
     stop_glerror();
 }
 
@@ -378,6 +384,8 @@ BOOL LLGLSLShader::createShader(std::vector<LLStaticHashedString> * attributes,
                                 U32 varying_count,
                                 const char** varyings)
 {
+    unloadInternal();
+
     sInstances.insert(this);
 
     //reloading, reset matrix hash values
diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h
index 5abddf274b4..0746e8760ab 100755
--- a/indra/llrender/llglslshader.h
+++ b/indra/llrender/llglslshader.h
@@ -198,7 +198,9 @@ class LLGLSLShader
 	bool mTextureStateFetched;
 	std::vector<U32> mTextureMagFilter;
 	std::vector<U32> mTextureMinFilter;
-	
+
+private:
+	void unloadInternal();
 };
 
 //UI shader (declared here so llui_libtest will link properly)
-- 
GitLab