+2012-06-22 Vladimir Serbinenko <phcoder@gmail.com>
+
+ * grub-core/kern/mm.c (grub_free): Fix agglomerating of free regions.
+
2012-06-22 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/mm.c (get_header_from_pointer): Put a more informative
}
else
{
- grub_mm_header_t q;
+ grub_mm_header_t q, s;
#if 0
q = r->first;
while (q != r->first);
#endif
- for (q = r->first; q >= p || q->next <= p; q = q->next)
+ for (s = r->first, q = s->next; q <= p || q->next >= p; s = q, q = s->next)
{
if (q->magic != GRUB_MM_FREE_MAGIC)
grub_fatal ("free magic is broken at %p: 0x%x", q, q->magic);
- if (q >= q->next && (q < p || q->next > p))
+ if (q <= q->next && (q > p || q->next < p))
break;
}
p->next = q->next;
q->next = p;
- if (p + p->size == p->next)
+ if (p->next + p->next->size == p)
{
- if (p->next == q)
- q = p;
+ p->magic = 0;
- p->next->magic = 0;
- p->size += p->next->size;
- p->next = p->next->next;
+ p->next->size += p->size;
+ q->next = p->next;
+ p = p->next;
}
- if (q + q->size == p)
+ r->first = q;
+
+ if (q == p + p->size)
{
- p->magic = 0;
- q->size += p->size;
- q->next = p->next;
+ q->magic = 0;
+ p->size += q->size;
+ if (q == s)
+ s = p;
+ s->next = p;
+ q = s;
}
r->first = q;