summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <tsdgeos@terra.es>2012-06-24 17:03:38 (GMT)
committerAlbert Astals Cid <tsdgeos@terra.es>2012-06-24 17:06:02 (GMT)
commit54b3cfb102d1198001d71b024039b24c0c166bfa (patch)
treeeaa4235f982c10f4d00d76a2a16ccbf68f19dc91
parentaeb20f56160a2b229bed9cf2db9d5b43d6dac993 (diff)
Fix underflwo in memoryToFree found by Fabio
(cherry picked from commit fb5a1783111070c6bd62a00f50f0efc9c919d241)
-rw-r--r--core/document.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/core/document.cpp b/core/document.cpp
index 3d40e8d..f151a69 100644
--- a/core/document.cpp
+++ b/core/document.cpp
@@ -217,8 +217,14 @@ void DocumentPrivate::cleanupPixmapMemory( qulonglong /*sure? bytesOffset*/ )
{
// update internal variables
pIt = m_allocatedPixmapsFifo.erase( pIt );
+ // m_allocatedPixmapsTotalMemory can't underflow because we always add or remove
+ // the memory used by the AllocatedPixmap so at most it can reach zero
m_allocatedPixmapsTotalMemory -= p->memory;
- memoryToFree -= p->memory;
+ // Make sure memoryToFree does not underflow
+ if ( p->memory > memoryToFree )
+ memoryToFree = 0;
+ else
+ memoryToFree -= p->memory;
pagesFreed++;
// delete pixmap
m_pagesVector.at( p->page )->deletePixmap( p->id );