From 5a4933ff7fd20ef03956f1063317b22bde1bb445 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 10 Feb 1989 09:18:19 +0000 Subject: [PATCH] Try to allocate to the next power of 2, instead of just aligning with GRABSIZE; This way, malloc(1000000) followed by free() followed by another malloc(1000000) will result in the same block being allocated, because first_present will now find it --- modules/src/malloc/mal.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/src/malloc/mal.c b/modules/src/malloc/mal.c index cf8924458..44a19266e 100644 --- a/modules/src/malloc/mal.c +++ b/modules/src/malloc/mal.c @@ -67,10 +67,10 @@ malloc(n) assert(n1 < (1 << LOG_MAX_SIZE)); min_class = 0; - while (n1 >= MIN_SIZE) { + do { n1 >>= 1; min_class++; - } + } while (n1 >= MIN_SIZE); } if (min_class >= MAX_FLIST) @@ -81,7 +81,8 @@ malloc(n) register char *p; #define GRABSIZE 4096 /* Power of 2 */ register unsigned int req = - (n+mallink_size()+GRABSIZE-1)&~(GRABSIZE-1); + ((MIN_SIZE<