- fb_end = fb->base + fb->size;
- if (fb->base <= a->base) {
- /* The alloc is within the free block. Now we need to know
- if it sticks out at either end. */
- if (fb_end == a_end) {
- if (fb->base == a->base) {
- /* fb and a are identical, so just free fb */
- prev_fb->next = fb->next;
- stgFree(fb);
- fb = prev_fb->next;
+ if (fb == NULL) {
+ /* If we have nothing left in fb, then neither a nor
+ anything later in the list is freeable, so we are done. */
+ break;
+ }
+ else {
+ fb_end = fb->base + fb->size;
+ /* We have a candidate fb. But does it really cover a? */
+ if (fb->base <= a->base) {
+ /* Yes, the alloc is within the free block. Now we need
+ to know if it sticks out at either end. */
+ if (fb_end == a_end) {
+ if (fb->base == a->base) {
+ /* fb and a are identical, so just free fb */
+ prev_fb->next = fb->next;
+ stgFree(fb);
+ fb = prev_fb->next;
+ }
+ else {
+ /* fb begins earlier, so truncate it to not include a */
+ fb->size = a->base - fb->base;
+ }