From d3a1c4cda49cc1b113abbdb175c557456581efac Mon Sep 17 00:00:00 2001
From: andreykproductengine <andreykproductengine@lindenlab.com>
Date: Tue, 6 Jun 2017 16:06:28 +0300
Subject: [PATCH] MAINT-7462 check pointer to avoid allocation crash in
 llpluginclassmedia

---
 indra/llplugin/llpluginclassmedia.cpp |  9 ++++++++-
 indra/newview/llviewermedia.cpp       | 29 +++++++++++++++------------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/indra/llplugin/llpluginclassmedia.cpp b/indra/llplugin/llpluginclassmedia.cpp
index f1b6fe0a124..680017204c0 100644
--- a/indra/llplugin/llpluginclassmedia.cpp
+++ b/indra/llplugin/llpluginclassmedia.cpp
@@ -224,7 +224,14 @@ void LLPluginClassMedia::idle(void)
 				void *addr = mPlugin->getSharedMemoryAddress(mTextureSharedMemoryName);
 
 				// clear texture memory to avoid random screen visual fuzz from uninitialized texture data
-				memset( addr, 0x00, newsize );
+				if (addr)
+				{
+					memset( addr, 0x00, newsize );
+				}
+				else
+				{
+					LL_WARNS("Plugin") << "Failed to get previously created shared memory address: " << mTextureSharedMemoryName << " size: " << mTextureSharedMemorySize << LL_ENDL;
+				}
 
 				// We could do this to force an update, but textureValid() will still be returning false until the first roundtrip to the plugin,
 				// so it may not be worthwhile.
diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp
index 9f05ee61bde..01b0dd0077b 100644
--- a/indra/newview/llviewermedia.cpp
+++ b/indra/newview/llviewermedia.cpp
@@ -3052,20 +3052,23 @@ void LLViewerMediaImpl::update()
 					data = mMediaSource->getBitsData();
 				}
 
-				// Offset the pixels pointer to match x_pos and y_pos
-				data += ( x_pos * mMediaSource->getTextureDepth() * mMediaSource->getBitsWidth() );
-				data += ( y_pos * mMediaSource->getTextureDepth() );
-
+				if(data != NULL)
 				{
-					LL_RECORD_BLOCK_TIME(FTM_MEDIA_SET_SUBIMAGE);
-					placeholder_image->setSubImage(
-							data,
-							mMediaSource->getBitsWidth(),
-							mMediaSource->getBitsHeight(),
-							x_pos,
-							y_pos,
-							width,
-							height);
+					// Offset the pixels pointer to match x_pos and y_pos
+					data += ( x_pos * mMediaSource->getTextureDepth() * mMediaSource->getBitsWidth() );
+					data += ( y_pos * mMediaSource->getTextureDepth() );
+
+					{
+						LL_RECORD_BLOCK_TIME(FTM_MEDIA_SET_SUBIMAGE);
+									placeholder_image->setSubImage(
+									data,
+									mMediaSource->getBitsWidth(),
+									mMediaSource->getBitsHeight(),
+									x_pos,
+									y_pos,
+									width,
+									height);
+					}
 				}
 
 			}
-- 
GitLab