if(n->sblock.closer)
{
// get the prev node
struct heap_block *pn = (struct heap_block *)((unsigned char *)n - n->sblock.closer);
// check if the prev node is cua_free
if( pn->sblock.region == 0 )
{
// yes, the prev one is cua_free
// combine with the prev one
pn->sblock.length += n->sblock.length;
n = pn;
f = true;
}
}
// get the next node
ln = (struct heap_block *)((unsigned char *)n + n->sblock.length);
if( __ptr_distance(hdr, ln) < hdr->size )
{
// check if the next node is cua_free
if(ln->sblock.region == 0)
{
// yes, the next one is cua_free
n->sblock.length += ln->sblock.length;
__heap_take_away(hdr, ln);
ft = true;
}
}
if(f || ft)
{
// fill closer of the next one
struct heap_block *nn = (struct heap_block *)((unsigned char *)n + n->sblock.length);
if( __ptr_distance(hdr, nn) < hdr->size )
nn->sblock.closer = n->sblock.length;
}