diff options
| author | andreykproductengine <andreykproductengine@lindenlab.com> | 2018-07-26 20:06:26 +0300 |
|---|---|---|
| committer | andreykproductengine <andreykproductengine@lindenlab.com> | 2018-07-26 20:06:26 +0300 |
| commit | e24d4c9f4d2f37ee80685c6ab276633b94b366b8 (patch) | |
| tree | d78c2549bb124973e87cce4f53273fd7a2e01687 /indra/llimage/llimagejpeg.cpp | |
| parent | 8c8a44f430cc373d3a09308c5efdc420c1571d11 (diff) | |
MAINT-8923 Better allocation failure handling, createGLTexture crashes
Diffstat (limited to 'indra/llimage/llimagejpeg.cpp')
| -rw-r--r-- | indra/llimage/llimagejpeg.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/indra/llimage/llimagejpeg.cpp b/indra/llimage/llimagejpeg.cpp index 60b2d0faa5..5c8b63a493 100644 --- a/indra/llimage/llimagejpeg.cpp +++ b/indra/llimage/llimagejpeg.cpp @@ -256,7 +256,10 @@ bool LLImageJPEG::decode(LLImageRaw* raw_image, F32 decode_time) setSize(cinfo.image_width, cinfo.image_height, 3); // Force to 3 components (RGB) - raw_image->resize(getWidth(), getHeight(), getComponents()); + if (!raw_image->resize(getWidth(), getHeight(), getComponents())) + { + throw std::bad_alloc(); + } raw_image_data = raw_image->getData(); @@ -311,6 +314,13 @@ bool LLImageJPEG::decode(LLImageRaw* raw_image, F32 decode_time) jpeg_destroy_decompress(&cinfo); } + catch (std::bad_alloc) + { + setLastError( "Out of memory"); + jpeg_destroy_decompress(&cinfo); + return true; // done + } + catch (int) { jpeg_destroy_decompress(&cinfo); @@ -370,7 +380,7 @@ boolean LLImageJPEG::encodeEmptyOutputBuffer( j_compress_ptr cinfo ) // Double the buffer size; S32 new_buffer_size = self->mOutputBufferSize * 2; - U8* new_buffer = new U8[ new_buffer_size ]; + U8* new_buffer = new(std::nothrow) U8[ new_buffer_size ]; if (!new_buffer) { LL_ERRS() << "Out of memory in LLImageJPEG::encodeEmptyOutputBuffer( j_compress_ptr cinfo )" << LL_ENDL; @@ -493,7 +503,14 @@ bool LLImageJPEG::encode( const LLImageRaw* raw_image, F32 encode_time ) disclaimMem(mOutputBufferSize); mOutputBufferSize = getWidth() * getHeight() * getComponents() + 1024; claimMem(mOutputBufferSize); - mOutputBuffer = new U8[ mOutputBufferSize ]; + mOutputBuffer = new(std::nothrow) U8[ mOutputBufferSize ]; + if (mOutputBuffer == NULL) + { + disclaimMem(mOutputBufferSize); + mOutputBufferSize = 0; + setLastError("Failed to allocate output buffer"); + return false; + } const U8* raw_image_data = NULL; S32 row_stride = 0; |
