realloc(): put an absolute upper limit on slack
authorH. Peter Anvin <hpa@zytor.com>
Wed, 27 Feb 2008 20:44:52 +0000 (12:44 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 27 Feb 2008 20:44:52 +0000 (12:44 -0800)
With loadfile() doing megabyte-sized trial-and-error allocations, we
want to be able to do really set the size on the final allocation;
thus constrain the amount of permitted slack to 4K max.

com32/lib/realloc.c

index 89b63c8..2161a75 100644 (file)
@@ -31,7 +31,8 @@ void *realloc(void *ptr, size_t size)
   /* Add the obligatory arena header, and round up */
   newsize = (size+2*sizeof(struct arena_header)-1) & ARENA_SIZE_MASK;
 
-  if ( oldsize >= newsize && newsize >= (oldsize >> 2) ) {
+  if ( oldsize >= newsize && newsize >= (oldsize >> 2) &&
+       oldsize-newsize < 4096 ) {
     /* This allocation is close enough already. */
     return ptr;
   } else {