summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandreykproductengine <andreykproductengine@lindenlab.com>2017-12-05 17:54:17 +0200
committerandreykproductengine <andreykproductengine@lindenlab.com>2017-12-05 17:54:17 +0200
commit34d3b49d1f6ae7e07d615cb1f98d5ad45fbb638d (patch)
treede90688685a1b0ff5a02e806987075cff4ffb390
parent8bceb809022981221baa288df673fbb2c59cdd04 (diff)
MAINT-2124 Texture allocation issues
-rw-r--r--indra/llimage/llimagej2c.cpp25
-rw-r--r--indra/newview/lltexturecache.cpp41
-rw-r--r--indra/newview/lltexturefetch.cpp16
3 files changed, 56 insertions, 26 deletions
diff --git a/indra/llimage/llimagej2c.cpp b/indra/llimage/llimagej2c.cpp
index 68694496bc..c40df009d8 100644
--- a/indra/llimage/llimagej2c.cpp
+++ b/indra/llimage/llimagej2c.cpp
@@ -369,19 +369,28 @@ bool LLImageJ2C::loadAndValidate(const std::string &filename)
else
{
U8 *data = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), file_size);
- apr_size_t bytes_read = file_size;
- apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
- infile.close() ;
-
- if (s != APR_SUCCESS || (S32)bytes_read != file_size)
+ if (!data)
{
- FREE_MEM(LLImageBase::getPrivatePool(), data);
- setLastError("Unable to read entire file");
+ infile.close();
+ setLastError("Out of memory", filename);
res = false;
}
else
{
- res = validate(data, file_size);
+ apr_size_t bytes_read = file_size;
+ apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
+ infile.close();
+
+ if (s != APR_SUCCESS || (S32)bytes_read != file_size)
+ {
+ FREE_MEM(LLImageBase::getPrivatePool(), data);
+ setLastError("Unable to read entire file");
+ res = false;
+ }
+ else
+ {
+ res = validate(data, file_size);
+ }
}
}
diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp
index 435d833345..6da6aba4fb 100644
--- a/indra/newview/lltexturecache.cpp
+++ b/indra/newview/lltexturecache.cpp
@@ -452,27 +452,38 @@ bool LLTextureCacheRemoteWorker::doRead()
size = llmin(size, mDataSize);
// Allocate the read buffer
mReadData = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), size);
- S32 bytes_read = LLAPRFile::readEx(mCache->mHeaderDataFileName,
- mReadData, offset, size, mCache->getLocalAPRFilePool());
- if (bytes_read != size)
+ if (mReadData)
+ {
+ S32 bytes_read = LLAPRFile::readEx(mCache->mHeaderDataFileName,
+ mReadData, offset, size, mCache->getLocalAPRFilePool());
+ if (bytes_read != size)
+ {
+ LL_WARNS() << "LLTextureCacheWorker: " << mID
+ << " incorrect number of bytes read from header: " << bytes_read
+ << " / " << size << LL_ENDL;
+ FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
+ mReadData = NULL;
+ mDataSize = -1; // failed
+ done = true;
+ }
+ // If we already read all we expected, we're actually done
+ if (mDataSize <= bytes_read)
+ {
+ done = true;
+ }
+ else
+ {
+ mState = BODY;
+ }
+ }
+ else
{
LL_WARNS() << "LLTextureCacheWorker: " << mID
- << " incorrect number of bytes read from header: " << bytes_read
- << " / " << size << LL_ENDL;
- FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
+ << " failed to allocate memory for reading: " << mDataSize << LL_ENDL;
mReadData = NULL;
mDataSize = -1; // failed
done = true;
}
- // If we already read all we expected, we're actually done
- if (mDataSize <= bytes_read)
- {
- done = true;
- }
- else
- {
- mState = BODY;
- }
}
// Fourth state / stage : read the rest of the data from the UUID based cached file
diff --git a/indra/newview/lltexturefetch.cpp b/indra/newview/lltexturefetch.cpp
index f917faadd4..1f7796e6d0 100644
--- a/indra/newview/lltexturefetch.cpp
+++ b/indra/newview/lltexturefetch.cpp
@@ -1760,7 +1760,17 @@ bool LLTextureFetchWorker::doWork(S32 param)
mRequestedSize -= src_offset; // Make requested values reflect useful part
mRequestedOffset += src_offset;
}
-
+
+ U8 * buffer = (U8 *)ALLOCATE_MEM(LLImageBase::getPrivatePool(), total_size);
+ if (!buffer)
+ {
+ // abort. If we have no space for packet, we have not enough space to decode image
+ setState(DONE);
+ LL_WARNS(LOG_TXT) << mID << " abort: out of memory" << LL_ENDL;
+ releaseHttpSemaphore();
+ return true;
+ }
+
if (mFormattedImage.isNull())
{
// For now, create formatted image based on extension
@@ -1780,10 +1790,10 @@ bool LLTextureFetchWorker::doWork(S32 param)
{
mFileSize = total_size + 1 ; //flag the file is not fully loaded.
}
-
- U8 * buffer = (U8 *) ALLOCATE_MEM(LLImageBase::getPrivatePool(), total_size);
+
if (cur_size > 0)
{
+ // Copy previously collected data into buffer
memcpy(buffer, mFormattedImage->getData(), cur_size);
}
mHttpBufferArray->read(src_offset, (char *) buffer + cur_size, append_size);