From 5a6e39c28f9814c6464f1785173e6a7883b92991 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 28 Feb 2012 01:32:38 +0100 Subject: [PATCH] * grub-core/lib/relocator.c (malloc_in_range): Fix memory leak. Change order of allocations to decrease fragmentation. --- ChangeLog | 5 +++++ grub-core/lib/relocator.c | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fc6e062f5..73d23caf5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-02-27 Vladimir Serbinenko + + * grub-core/lib/relocator.c (malloc_in_range): Fix memory leak. + Change order of allocations to decrease fragmentation. + 2012-02-27 Vladimir Serbinenko * Makefile.util.def (grub-ofpathname): Enable on all platforms. diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index c08fb958e..b391f0575 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -495,9 +495,9 @@ malloc_in_range (struct grub_relocator *rel, } #endif - events = grub_malloc (maxevents * sizeof (events[0])); eventt = grub_malloc (maxevents * sizeof (events[0])); counter = grub_malloc ((DIGITSORT_MASK + 2) * sizeof (counter[0])); + events = grub_malloc (maxevents * sizeof (events[0])); if (!events || !eventt || !counter) { grub_dprintf ("relocator", "events or counter allocation failed %d\n", @@ -939,6 +939,9 @@ malloc_in_range (struct grub_relocator *rel, /* Malloc is available again. */ grub_mm_base = base_saved; + grub_free (eventt); + grub_free (counter); + { int last_start = 0; int inreg = 0, regbeg = 0, ncol = 0; @@ -1165,12 +1168,17 @@ malloc_in_range (struct grub_relocator *rel, free_subchunk (&res->subchunks[i]); grub_free (res->subchunks); grub_dprintf ("relocator", "allocation failed with out-of-memory\n"); + grub_free (events); + return 0; } } res->src = target; res->size = size; + + grub_free (events); + grub_dprintf ("relocator", "allocated: 0x%lx+0x%lx\n", (unsigned long) target, (unsigned long) size);