about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/custommem.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 7f176fa3..80adb476 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -96,7 +96,9 @@ static size_t 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);
+            maxsize = m->prev.size;
+            if(maxsize>sizeof(blockmark_t))
+                maxsize -= sizeof(blockmark_t);
             if((uintptr_t)block+maxsize>(uintptr_t)m)
                 return maxsize; // no block large enough left...
         }