fix needed mem check

Origin commit data
------------------
Commit: 833a65c9e4
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2017-03-23 (Thu, 23 Mar 2017)
This commit is contained in:
Jacek Jendrzej
2017-03-23 12:43:27 +01:00
parent e7eb5ee437
commit 0ed64a8b8b

View File

@@ -170,7 +170,8 @@ bool CPictureViewer::DecodeImage (const std::string & _name, bool showBusySign,
m_NextPic_Buffer = NULL;
}
size_t bufsize = x * y * 3;
if (!checkfreemem(bufsize)){
size_t resizeBuf = (m_endx - m_startx) * (m_endy - m_starty)*3;
if (!checkfreemem(bufsize + resizeBuf)){
return false;
}
m_NextPic_Buffer = (unsigned char *) malloc (bufsize);
@@ -856,8 +857,8 @@ bool CPictureViewer::checkfreemem(size_t bufsize)
{
struct sysinfo info;
sysinfo( &info );
if(bufsize*2 + 4096 > (size_t)info.freeram + (size_t)info.freeswap){
dprintf(DEBUG_NORMAL, "[CPictureViewer] [%s - %d] Error: Out of memory\n", __func__, __LINE__);
if(bufsize + 4096 > (size_t)info.freeram + (size_t)info.freeswap){
dprintf(DEBUG_NORMAL, "[CPictureViewer] [%s - %d] Error: Out of memory: need %zu > free %zu\n", __func__, __LINE__,bufsize,(size_t)info.freeram + (size_t)info.freeswap);
return false;
}
return true;