From b10e46167b7aa3b44c4d2fb3fcdcbdc4f6e11096 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Mon, 29 Jan 2018 12:40:44 +0000
Subject: [PATCH] MAINT-8234 Mesh tread protections and removed unnecessary try
 in staticRun()

---
 indra/llcommon/llthread.cpp        | 58 +++++++++++-------------------
 indra/newview/llmeshrepository.cpp | 21 +++++++++--
 2 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp
index b96b2ce4bcb..e353230791b 100644
--- a/indra/llcommon/llthread.cpp
+++ b/indra/llcommon/llthread.cpp
@@ -129,50 +129,32 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap
 
     sThreadID = threadp->mID;
 
-    try
+    // Run the user supplied function
+    do 
     {
-        // Run the user supplied function
-        do 
+        try
         {
-            try
-            {
-                threadp->run();
-            }
-            catch (const LLContinueError &e)
-            {
-                LL_WARNS("THREAD") << "ContinueException on thread '" << threadp->mName <<
-                    "' reentering run(). Error what is: '" << e.what() << "'" << LL_ENDL;
-                //output possible call stacks to log file.
-                LLError::LLCallStacks::print();
-
-                LOG_UNHANDLED_EXCEPTION("LLThread");
-                continue;
-            }
-            break;
-
-        } while (true);
+            threadp->run();
+        }
+        catch (const LLContinueError &e)
+        {
+            LL_WARNS("THREAD") << "ContinueException on thread '" << threadp->mName <<
+                "' reentering run(). Error what is: '" << e.what() << "'" << LL_ENDL;
+            //output possible call stacks to log file.
+            LLError::LLCallStacks::print();
 
-        //LL_INFOS() << "LLThread::staticRun() Exiting: " << threadp->mName << LL_ENDL;
+            LOG_UNHANDLED_EXCEPTION("LLThread");
+            continue;
+        }
+        break;
 
-        // We're done with the run function, this thread is done executing now.
-        //NB: we are using this flag to sync across threads...we really need memory barriers here
-        threadp->mStatus = STOPPED;
-    }
-    catch (std::bad_alloc)
-    {
-        threadp->mStatus = CRASHED;
-        LLMemory::logMemoryInfo(TRUE);
+    } while (true);
 
-        //output possible call stacks to log file.
-        LLError::LLCallStacks::print();
+    //LL_INFOS() << "LLThread::staticRun() Exiting: " << threadp->mName << LL_ENDL;
 
-        LL_ERRS("THREAD") << "Bad memory allocation in LLThread::staticRun() named '" << threadp->mName << "'!" << LL_ENDL;
-    }
-    catch (...)
-    {
-        threadp->mStatus = CRASHED;
-        CRASH_ON_UNHANDLED_EXCEPTION("LLThread");
-    }
+    // We're done with the run function, this thread is done executing now.
+    //NB: we are using this flag to sync across threads...we really need memory barriers here
+    threadp->mStatus = STOPPED;
 
     delete threadp->mRecorder;
     threadp->mRecorder = NULL;
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index 51ca7a8a514..fdaa28b22b4 100644
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -1224,7 +1224,12 @@ bool LLMeshRepoThread::fetchMeshSkinInfo(const LLUUID& mesh_id)
 				LLMeshRepository::sCacheBytesRead += size;
 				++LLMeshRepository::sCacheReads;
 				file.seek(offset);
-				U8* buffer = new U8[size];
+				U8* buffer = new(std::nothrow) U8[size];
+				if (!buffer)
+				{
+					LL_WARNS(LOG_MESH) << "Failed to allocate memory for skin info" << LL_ENDL;
+					return false;
+				}
 				file.read(buffer, size);
 
 				//make sure buffer isn't all 0's by checking the first 1KB (reserved block but not written)
@@ -1316,7 +1321,12 @@ bool LLMeshRepoThread::fetchMeshDecomposition(const LLUUID& mesh_id)
 				++LLMeshRepository::sCacheReads;
 
 				file.seek(offset);
-				U8* buffer = new U8[size];
+				U8* buffer = new(std::nothrow) U8[size];
+				if (!buffer)
+				{
+					LL_WARNS(LOG_MESH) << "Failed to allocate memory for mesh decomposition" << LL_ENDL;
+					return false;
+				}
 				file.read(buffer, size);
 
 				//make sure buffer isn't all 0's by checking the first 1KB (reserved block but not written)
@@ -1407,7 +1417,12 @@ bool LLMeshRepoThread::fetchMeshPhysicsShape(const LLUUID& mesh_id)
 				LLMeshRepository::sCacheBytesRead += size;
 				++LLMeshRepository::sCacheReads;
 				file.seek(offset);
-				U8* buffer = new U8[size];
+				U8* buffer = new(std::nothrow) U8[size];
+				if (!buffer)
+				{
+					LL_WARNS(LOG_MESH) << "Failed to allocate memory for physics shape" << LL_ENDL;
+					return false;
+				}
 				file.read(buffer, size);
 
 				//make sure buffer isn't all 0's by checking the first 1KB (reserved block but not written)
-- 
GitLab