From 275ad3fdabf8417376e01a4a994d4a78dba6f15f Mon Sep 17 00:00:00 2001
From: Alexander Gavriliuk <alexandrgproductengine@lindenlab.com>
Date: Tue, 21 Mar 2023 01:37:51 +0100
Subject: [PATCH] SL-19266 Potential Use-After-Free in LLImageGL::setImage

---
 indra/llrender/llimagegl.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 9dc140b5b98..465f30a3432 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -859,9 +859,16 @@ BOOL LLImageGL::setImage(const U8* data_in, BOOL data_hasmips /* = FALSE */, S32
 							stop_glerror();
 
 							if (prev_mip_data)
-								delete[] prev_mip_data;
+							{
+								if (prev_mip_data != cur_mip_data)
+									delete[] prev_mip_data;
+								prev_mip_data = nullptr;
+							}
 							if (cur_mip_data)
+							{
 								delete[] cur_mip_data;
+								cur_mip_data = nullptr;
+							}
 							
 							mGLTextureCreated = false;
 							return FALSE;
-- 
GitLab