From 26533fe6bca59e340fe33c658c0a3c8aca3f04ff Mon Sep 17 00:00:00 2001 From: Andrei Borzenkov Date: Tue, 12 Jan 2016 22:36:53 +0300 Subject: [PATCH] normal: fix memory leak Found by: Coverity scan. CID: 96641, 96670, 96667 --- grub-core/normal/menu_entry.c | 7 ++++++- grub-core/normal/term.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index 2b732250d..b80d161dd 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -476,7 +476,10 @@ insert_string (struct screen *screen, const char *s, int update) (grub_uint8_t *) s, (p - s), 0); if (! ensure_space (current_linep, size)) - return 0; + { + grub_free (unicode_msg); + return 0; + } grub_memmove (current_linep->buf + screen->column + size, current_linep->buf + screen->column, @@ -1265,6 +1268,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) if (! screen->lines[i].pos) { grub_print_error (); + destroy_screen (screen); grub_errno = GRUB_ERR_NONE; return; } @@ -1274,6 +1278,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) if (!screen->terms) { grub_print_error (); + destroy_screen (screen); grub_errno = GRUB_ERR_NONE; return; } diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c index 4c2238b25..ac5d69f0f 100644 --- a/grub-core/normal/term.c +++ b/grub-core/normal/term.c @@ -77,8 +77,6 @@ print_more (void) grub_term_output_t term; grub_uint32_t *unicode_str, *unicode_last_position; - pos = grub_term_save_pos (); - /* TRANSLATORS: This has to fit on one line. It's ok to include few words but don't write poems. */ grub_utf8_to_ucs4_alloc (_("--MORE--"), &unicode_str, @@ -90,6 +88,8 @@ print_more (void) return; } + pos = grub_term_save_pos (); + grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); FOR_ACTIVE_TERM_OUTPUTS(term)