SL-10908 One more safeguard

meow-7.2.2
andreykproductengine 2019-08-05 20:52:18 +03:00
parent 301c5ae4e2
commit 55983b9abd
1 changed files with 16 additions and 8 deletions

View File

@ -2178,19 +2178,27 @@ bool LLImageFormatted::load(const std::string &filename, int load_size)
}
bool res;
U8 *data = allocateData(load_size);
apr_size_t bytes_read = load_size;
apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
if (s != APR_SUCCESS || (S32) bytes_read != load_size)
if (data)
{
deleteData();
setLastError("Unable to read file",filename);
res = false;
apr_size_t bytes_read = load_size;
apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
if (s != APR_SUCCESS || (S32) bytes_read != load_size)
{
deleteData();
setLastError("Unable to read file",filename);
res = false;
}
else
{
res = updateData();
}
}
else
{
res = updateData();
setLastError("Allocation failure", filename);
res = false;
}
return res;
}