The purpose of thesection is to find the free block before or after the current block and join those two blocks together, to reduce heap fragmentation.Code:for (p = freeptr; !(bp > p && bp < p->s.ptr); p = p->s.ptr) /*if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) { printf("in the corner\n"); break; freed block at start or end of arena }*/
[At least, that's what it looks like].
Obviously, falling off the edge of mymalloc is a bad thing, and a good compiler should spot that there's a possibility of that. If you don't want to break a new block of "OS" memory, then at least return NULL.
--
Mats