Fix several memory leaks.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-05-04 13:47:10 +02:00
parent c686014c1b
commit 03f7c8c304
13 changed files with 72 additions and 14 deletions

View file

@ -1,3 +1,7 @@
2013-05-04 Vladimir Serbinenko <phcoder@gmail.com>
Fix several memory leaks.
2013-05-04 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/menu.c (run_menu): Fix timeout reference point.

View file

@ -70,6 +70,8 @@ grub_font_draw_string (const char *str, grub_font_t font,
return err;
}
for (ptr = visual; ptr < visual + visual_len; ptr++)
grub_free (ptr->combining);
grub_free (visual);
return GRUB_ERR_NONE;

View file

@ -85,7 +85,7 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested)
|| cached_view->screen.width != mode_info.width
|| cached_view->screen.height != mode_info.height)
{
grub_free (cached_view);
grub_gfxmenu_view_destroy (cached_view);
/* Create the view. */
cached_view = grub_gfxmenu_view_new (full_theme_path ? : theme_path,
mode_info.width,

View file

@ -83,7 +83,10 @@ list_destroy (void *vself)
self->selected_item_box->destroy (self->selected_item_box);
if (self->icon_manager)
grub_gfxmenu_icon_manager_destroy (self->icon_manager);
if (self->scrollbar_thumb)
self->scrollbar_thumb->destroy (self->scrollbar_thumb);
if (self->scrollbar_frame)
self->scrollbar_frame->destroy (self->scrollbar_frame);
grub_free (self);
}

View file

@ -185,6 +185,7 @@ draw_text (grub_gui_progress_bar_t self)
int y = ((height - grub_font_get_descent (font)) / 2
+ grub_font_get_ascent (font) / 2);
grub_font_draw_string (text, font, text_color, x, y);
grub_free (text);
}
}

View file

@ -139,6 +139,8 @@ grub_env_context_close (void)
grub_current_context = context;
menu = current_menu->prev;
if (current_menu->menu)
grub_normal_free_menu (current_menu->menu);
grub_free (current_menu);
current_menu = menu;

View file

@ -127,6 +127,7 @@ grub_normal_free_menu (grub_menu_t menu)
grub_free ((void *) entry->users);
grub_free ((void *) entry->title);
grub_free ((void *) entry->sourcecode);
grub_free (entry);
entry = next_entry;
}
@ -191,6 +192,7 @@ read_config_file (const char *config)
if (ptr)
*ptr = 0;
grub_env_set ("config_directory", config_dir);
grub_free (config_dir);
grub_env_export ("config_file");
grub_env_export ("config_directory");

View file

@ -517,7 +517,15 @@ destroy_screen (struct screen *screen)
struct line *linep = screen->lines + i;
if (linep)
{
unsigned j;
if (linep->pos)
for (j = 0; j < screen->nterms; j++)
grub_free (linep->pos[j]);
grub_free (linep->buf);
grub_free (linep->pos);
}
}
grub_free (screen->killed_text);

View file

@ -56,8 +56,10 @@ grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position,
while (str < last_position)
{
struct grub_unicode_glyph glyph;
glyph.combining = 0;
str += grub_unicode_aglomerate_comb (str, last_position - str, &glyph);
width += grub_term_getcharwidth (term, &glyph);
grub_free (glyph.combining);
}
return width;
}
@ -396,6 +398,7 @@ menu_text_print_timeout (int timeout, void *dataptr)
}
grub_print_message_indented (msg_translated, 3, 0, data->term);
grub_free (msg_translated);
posx = grub_term_getxy (data->term) >> 8;
grub_print_spaces (data->term, grub_term_width (data->term) - posx - 1);
@ -447,7 +450,7 @@ menu_text_fini (void *dataptr)
grub_term_setcursor (data->term, 1);
grub_term_cls (data->term);
grub_free (data);
}
static void

View file

@ -952,6 +952,8 @@ print_ucs4_real (const grub_uint32_t * str,
ret++;
if (visual_len_show && visual[visual_len_show - 1].base != '\n')
ret++;
for (vptr = visual; vptr < visual + visual_len; vptr++)
grub_free (vptr->combining);
grub_free (visual);
}
else

View file

@ -175,7 +175,11 @@ set_term_color (grub_uint8_t term_color)
static void
clear_char (struct grub_colored_char *c)
{
if (c->code)
{
grub_free (c->code->combining);
grub_free (c->code);
}
c->code = grub_unicode_glyph_from_code (' ');
if (!c->code)
grub_errno = GRUB_ERR_NONE;
@ -188,7 +192,18 @@ grub_virtual_screen_free (void)
{
/* If virtual screen has been allocated, free it. */
if (virtual_screen.text_buffer != 0)
{
unsigned i;
for (i = 0;
i < virtual_screen.columns * virtual_screen.rows;
i++)
if (virtual_screen.text_buffer[i].code)
{
grub_free (virtual_screen.text_buffer[i].code->combining);
grub_free (virtual_screen.text_buffer[i].code);
}
grub_free (virtual_screen.text_buffer);
}
/* Reset virtual screen data. */
grub_memset (&virtual_screen, 0, sizeof (virtual_screen));
@ -403,7 +418,11 @@ grub_gfxterm_term_fini (struct grub_term_output *term __attribute__ ((unused)))
for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++)
{
if (virtual_screen.text_buffer[i].code)
{
grub_free (virtual_screen.text_buffer[i].code->combining);
grub_free (virtual_screen.text_buffer[i].code);
}
virtual_screen.text_buffer[i].code = 0;
}
@ -798,7 +817,11 @@ scroll_up (void)
/* Clear first line in text buffer. */
for (i = 0; i < virtual_screen.columns; i++)
if (virtual_screen.text_buffer[i].code)
{
grub_free (virtual_screen.text_buffer[i].code->combining);
grub_free (virtual_screen.text_buffer[i].code);
}
/* Scroll text buffer with one line to up. */
grub_memmove (virtual_screen.text_buffer,
@ -874,7 +897,11 @@ grub_gfxterm_putchar (struct grub_term_output *term,
p = (virtual_screen.text_buffer +
virtual_screen.cursor_x +
virtual_screen.cursor_y * virtual_screen.columns);
if (p->code)
{
grub_free (p->code->combining);
grub_free (p->code);
}
p->code = grub_unicode_glyph_dup (c);
if (!p->code)
grub_errno = GRUB_ERR_NONE;
@ -889,7 +916,9 @@ grub_gfxterm_putchar (struct grub_term_output *term,
for (i = 1; i < char_width && p + i <
virtual_screen.text_buffer + virtual_screen.columns
* virtual_screen.rows; i++)
if (p[i].code)
{
grub_free (p[i].code->combining);
grub_free (p[i].code);
p[i].code = NULL;
}

View file

@ -87,7 +87,8 @@ failure_append_vtext(grub_test_failure_t failure, const char *fmt, va_list args)
char *oldmsg = failure->message;
failure->message = grub_xasprintf("%s%s", oldmsg, msg);
grub_free(oldmsg);
grub_free (oldmsg);
grub_free (msg);
}
else
{

View file

@ -115,6 +115,7 @@ grub_video_capture_get_framebuffer (void)
void
grub_video_capture_end (void)
{
grub_video_fb_delete_render_target (framebuffer.render_target);
grub_free (framebuffer.ptr);
grub_video_fb_fini ();
grub_video_adapter_active = saved;