diff --git a/src/custommem.c b/src/custommem.c index 23f5ba3d..6839e749 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -92,7 +92,9 @@ static int getMaxFreeBlock(void* block, size_t block_size) int maxsize = 0; while(m->prev.x32) { // while there is a subblock if(!m->prev.fill && m->prev.size>maxsize) { - maxsize = m->prev.size-sizeof(blockmark_t); // remove the marker + maxsize = m->prev.size; + if(maxsize>sizeof(blockmark_t)) // remove the marker + maxsize -= sizeof(blockmark_t); if((uintptr_t)block+maxsize>(uintptr_t)m) return maxsize; // no block large enough left... }