Skip to content

Commit

Permalink
* kern/mm.c (grub_mm_init_region): Check for region size after aligning
Browse files Browse the repository at this point in the history
	pointers.
  • Loading branch information
phcoder committed May 3, 2010
1 parent 2589383 commit 9b058d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2010-05-01 Vladimir Serbinenko <[email protected]>

* kern/mm.c (grub_mm_init_region): Check for region size after aligning
pointers.

2010-05-01 Vladimir Serbinenko <[email protected]>

* kern/mm.c (grub_real_malloc): Fix size calculation when extra == 0.
Expand Down
11 changes: 5 additions & 6 deletions kern/mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,14 @@ grub_mm_init_region (void *addr, grub_size_t size)
grub_printf ("Using memory for heap: start=%p, end=%p\n", addr, addr + (unsigned int) size);
#endif

/* If this region is too small, ignore it. */
if (size < GRUB_MM_ALIGN * 2)
return;

/* Allocate a region from the head. */
r = (grub_mm_region_t) (((grub_addr_t) addr + GRUB_MM_ALIGN - 1)
& (~(GRUB_MM_ALIGN - 1)));
r = (grub_mm_region_t) ALIGN_UP ((grub_addr_t) addr, GRUB_MM_ALIGN);
size -= (char *) r - (char *) addr + sizeof (*r);

/* If this region is too small, ignore it. */
if (size < GRUB_MM_ALIGN)
return;

h = (grub_mm_header_t) ((char *) r + GRUB_MM_ALIGN);
h->next = h;
h->magic = GRUB_MM_FREE_MAGIC;
Expand Down

0 comments on commit 9b058d5

Please sign in to comment.