]> git.proxmox.com Git - grub2.git/commitdiff
* grub-core/kern/mm.c (grub_free): Fix agglomerating of free regions.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 22 Jun 2012 22:39:10 +0000 (00:39 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 22 Jun 2012 22:39:10 +0000 (00:39 +0200)
ChangeLog
grub-core/kern/mm.c

index 5f823b9e1370461d4253cee8f6a94df176bda23a..9161b4f16ce3727c3b82ef16861b1d6aa55b0a32 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+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
index 7f240779f832585f743f0c589575f190e33a737d..9f08e05bf5827b662abcdec34bacbe9297cf6eb8 100644 (file)
@@ -371,7 +371,7 @@ grub_free (void *ptr)
     }
   else
     {
-      grub_mm_header_t q;
+      grub_mm_header_t q, s;
 
 #if 0
       q = r->first;
@@ -384,12 +384,12 @@ grub_free (void *ptr)
       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;
        }
 
@@ -397,21 +397,25 @@ grub_free (void *ptr)
       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;