From c4ff0b48898de86b9ee8e198395e16a8429c8aa4 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Fri, 19 Jul 2024 20:17:37 +0300
Subject: viewer#2071 Properly handle 'out of memory' for meshes

---
 indra/llcharacter/llkeyframemotion.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

(limited to 'indra/llcharacter')

diff --git a/indra/llcharacter/llkeyframemotion.cpp b/indra/llcharacter/llkeyframemotion.cpp
index 6c060d7980..6790f1ad56 100644
--- a/indra/llcharacter/llkeyframemotion.cpp
+++ b/indra/llcharacter/llkeyframemotion.cpp
@@ -2227,7 +2227,12 @@ bool LLKeyframeMotion::dumpToFile(const std::string& name)
         }
 
         S32 file_size = getFileSize();
-        U8* buffer = new U8[file_size];
+        U8* buffer = new(std::nothrow) U8[file_size];
+        if (!buffer)
+        {
+            LLError::LLUserWarningMsg::showOutOfMemory();
+            LL_ERRS() << "Bad memory allocation for buffer, file: " << name << " " << file_size << LL_ENDL;
+        }
 
         LL_DEBUGS("BVH") << "Dumping " << outfilename << LL_ENDL;
         LLDataPackerBinaryBuffer dp(buffer, file_size);
@@ -2435,7 +2440,12 @@ void LLKeyframeMotion::onLoadComplete(const LLUUID& asset_uuid,
             LLFileSystem file(asset_uuid, type, LLFileSystem::READ);
             S32 size = file.getSize();
 
-            U8* buffer = new U8[size];
+            U8* buffer = new(std::nothrow) U8[size];
+            if (!buffer)
+            {
+                LLError::LLUserWarningMsg::showOutOfMemory();
+                LL_ERRS() << "Bad memory allocation for buffer of size: " << size << LL_ENDL;
+            }
             file.read((U8*)buffer, size);   /*Flawfinder: ignore*/
 
             LL_DEBUGS("Animation") << "Loading keyframe data for: " << motionp->getName() << ":" << motionp->getID() << " (" << size << " bytes)" << LL_ENDL;
-- 
cgit v1.2.3