@@ -1430,6 +1430,15 @@ void LLTexLayer::renderMorphMasks(S32 x, S32 y, S32 width, S32 height, const LLC
14301430 // We should only be doing this when we believe something has changed with respect to the user's appearance.
14311431 {
14321432 LL_DEBUGS (" Morph" ) << " gl alpha cache of morph mask not found, doing readback: " << getName () << LL_ENDL ;
1433+
1434+ // Replace the cached mask without leaking its old allocation.
1435+ alpha_cache_t ::iterator cached = mAlphaCache .find (cache_index);
1436+ if (cached != mAlphaCache .end ())
1437+ {
1438+ ll_aligned_free_32 (cached->second );
1439+ mAlphaCache .erase (cached);
1440+ }
1441+
14331442 // clear out a slot if we have filled our cache
14341443 S32 max_cache_entries = getTexLayerSet ()->getAvatarAppearance ()->isSelf () ? 4 : 1 ;
14351444 while ((S32 )mAlphaCache .size () >= max_cache_entries)
@@ -1466,6 +1475,7 @@ void LLTexLayer::renderMorphMasks(S32 x, S32 y, S32 width, S32 height, const LLC
14661475 U8 * temp = (U8 *)ll_aligned_malloc_32 (mem_size << 2 ); // allocate same size, but RGBA
14671476 if (!temp)
14681477 {
1478+ ll_aligned_free_32 (alpha_data);
14691479 LLError::LLUserWarningMsg::showOutOfMemory ();
14701480 LL_ERRS () << " Failed to allocate temporary memory for morph texture readback: " << (S32 )(mem_size << 2 ) << LL_ENDL ;
14711481 return ;
@@ -1508,6 +1518,7 @@ void LLTexLayer::renderMorphMasks(S32 x, S32 y, S32 width, S32 height, const LLC
15081518 U8 * temp_data = (U8 *)ll_aligned_malloc_32 (mem_size * TEMP_BYTES_PER_PIXEL );
15091519 if (!temp_data)
15101520 {
1521+ ll_aligned_free_32 (alpha_data);
15111522 LLError::LLUserWarningMsg::showOutOfMemory ();
15121523 LL_ERRS () << " Failed to allocate temporary memory for morph texture: " << (S32 )(mem_size * TEMP_BYTES_PER_PIXEL ) << LL_ENDL ;
15131524 return ;
0 commit comments