MAINT-2124 Texture allocation issues

Tue, 05 Dec 2017 17:54:17 +0200

author
andreykproductengine <andreykproductengine@lindenlab.com>
date
Tue, 05 Dec 2017 17:54:17 +0200
changeset 53551
e1eaaa165f25
parent 53550
a3c8abf0690b
child 53552
87c50836d294

MAINT-2124 Texture allocation issues

indra/llimage/llimagej2c.cpp file | annotate | diff | revisions
indra/newview/lltexturecache.cpp file | annotate | diff | revisions
indra/newview/lltexturefetch.cpp file | annotate | diff | revisions
     1.1 --- a/indra/llimage/llimagej2c.cpp	Wed Dec 06 16:57:08 2017 +0100
     1.2 +++ b/indra/llimage/llimagej2c.cpp	Tue Dec 05 17:54:17 2017 +0200
     1.3 @@ -374,19 +374,28 @@
     1.4  	else
     1.5  	{
     1.6  		U8 *data = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), file_size);
     1.7 -		apr_size_t bytes_read = file_size;
     1.8 -		apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read	
     1.9 -		infile.close() ;
    1.10 -
    1.11 -		if (s != APR_SUCCESS || (S32)bytes_read != file_size)
    1.12 +		if (!data)
    1.13  		{
    1.14 -			FREE_MEM(LLImageBase::getPrivatePool(), data);
    1.15 -			setLastError("Unable to read entire file");
    1.16 +			infile.close();
    1.17 +			setLastError("Out of memory", filename);
    1.18  			res = false;
    1.19  		}
    1.20  		else
    1.21  		{
    1.22 -			res = validate(data, file_size);
    1.23 +			apr_size_t bytes_read = file_size;
    1.24 +			apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read	
    1.25 +			infile.close();
    1.26 +
    1.27 +			if (s != APR_SUCCESS || (S32)bytes_read != file_size)
    1.28 +			{
    1.29 +				FREE_MEM(LLImageBase::getPrivatePool(), data);
    1.30 +				setLastError("Unable to read entire file");
    1.31 +				res = false;
    1.32 +			}
    1.33 +			else
    1.34 +			{
    1.35 +				res = validate(data, file_size);
    1.36 +			}
    1.37  		}
    1.38  	}
    1.39  	
     2.1 --- a/indra/newview/lltexturecache.cpp	Wed Dec 06 16:57:08 2017 +0100
     2.2 +++ b/indra/newview/lltexturecache.cpp	Tue Dec 05 17:54:17 2017 +0200
     2.3 @@ -452,27 +452,38 @@
     2.4  		size = llmin(size, mDataSize);
     2.5  		// Allocate the read buffer
     2.6  		mReadData = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), size);
     2.7 -		S32 bytes_read = LLAPRFile::readEx(mCache->mHeaderDataFileName, 
     2.8 -											 mReadData, offset, size, mCache->getLocalAPRFilePool());
     2.9 -		if (bytes_read != size)
    2.10 +		if (mReadData)
    2.11 +		{
    2.12 +			S32 bytes_read = LLAPRFile::readEx(mCache->mHeaderDataFileName, 
    2.13 +												 mReadData, offset, size, mCache->getLocalAPRFilePool());
    2.14 +			if (bytes_read != size)
    2.15 +			{
    2.16 +				LL_WARNS() << "LLTextureCacheWorker: "  << mID
    2.17 +						<< " incorrect number of bytes read from header: " << bytes_read
    2.18 +						<< " / " << size << LL_ENDL;
    2.19 +				FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
    2.20 +				mReadData = NULL;
    2.21 +				mDataSize = -1; // failed
    2.22 +				done = true;
    2.23 +			}
    2.24 +			// If we already read all we expected, we're actually done
    2.25 +			if (mDataSize <= bytes_read)
    2.26 +			{
    2.27 +				done = true;
    2.28 +			}
    2.29 +			else
    2.30 +			{
    2.31 +				mState = BODY;
    2.32 +			}
    2.33 +		}
    2.34 +		else
    2.35  		{
    2.36  			LL_WARNS() << "LLTextureCacheWorker: "  << mID
    2.37 -					<< " incorrect number of bytes read from header: " << bytes_read
    2.38 -					<< " / " << size << LL_ENDL;
    2.39 -			FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
    2.40 +				<< " failed to allocate memory for reading: " << mDataSize << LL_ENDL;
    2.41  			mReadData = NULL;
    2.42  			mDataSize = -1; // failed
    2.43  			done = true;
    2.44  		}
    2.45 -		// If we already read all we expected, we're actually done
    2.46 -		if (mDataSize <= bytes_read)
    2.47 -		{
    2.48 -			done = true;
    2.49 -		}
    2.50 -		else
    2.51 -		{
    2.52 -			mState = BODY;
    2.53 -		}
    2.54  	}
    2.55  
    2.56  	// Fourth state / stage : read the rest of the data from the UUID based cached file
     3.1 --- a/indra/newview/lltexturefetch.cpp	Wed Dec 06 16:57:08 2017 +0100
     3.2 +++ b/indra/newview/lltexturefetch.cpp	Tue Dec 05 17:54:17 2017 +0200
     3.3 @@ -1781,7 +1781,17 @@
     3.4  				mRequestedSize -= src_offset;			// Make requested values reflect useful part
     3.5  				mRequestedOffset += src_offset;
     3.6  			}
     3.7 -			
     3.8 +
     3.9 +			U8 * buffer = (U8 *)ALLOCATE_MEM(LLImageBase::getPrivatePool(), total_size);
    3.10 +			if (!buffer)
    3.11 +			{
    3.12 +				// abort. If we have no space for packet, we have not enough space to decode image
    3.13 +				setState(DONE);
    3.14 +				LL_WARNS(LOG_TXT) << mID << " abort: out of memory" << LL_ENDL;
    3.15 +				releaseHttpSemaphore();
    3.16 +				return true;
    3.17 +			}
    3.18 +
    3.19  			if (mFormattedImage.isNull())
    3.20  			{
    3.21  				// For now, create formatted image based on extension
    3.22 @@ -1801,10 +1811,10 @@
    3.23  			{
    3.24  				mFileSize = total_size + 1 ; //flag the file is not fully loaded.
    3.25  			}
    3.26 -			
    3.27 -			U8 * buffer = (U8 *) ALLOCATE_MEM(LLImageBase::getPrivatePool(), total_size);
    3.28 +
    3.29  			if (cur_size > 0)
    3.30  			{
    3.31 +				// Copy previously collected data into buffer
    3.32  				memcpy(buffer, mFormattedImage->getData(), cur_size);
    3.33  			}
    3.34  			mHttpBufferArray->read(src_offset, (char *) buffer + cur_size, append_size);

mercurial