From 1bff60e5aac71552aafe0dc5e08ff62ef32ee711 Mon Sep 17 00:00:00 2001 From: Andrei Borzenkov Date: Tue, 12 Jan 2016 20:37:43 +0300 Subject: [PATCH] nativedisk: fix memory leak Based on Coverity scan. CID: 96660 Extended to also cover other error return places. --- grub-core/commands/nativedisk.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c index b3bc4639c..345f97c4d 100644 --- a/grub-core/commands/nativedisk.c +++ b/grub-core/commands/nativedisk.c @@ -198,7 +198,10 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), return grub_errno; if (get_uuid (NULL, &uuid_root, 0)) - return grub_errno; + { + grub_free (mods); + return grub_errno; + } prefdev = grub_file_get_device_name (prefix); if (grub_errno) @@ -210,6 +213,8 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), if (get_uuid (prefdev, &uuid_prefix, 0)) { grub_free (uuid_root); + grub_free (prefdev); + grub_free (mods); return grub_errno; } @@ -289,12 +294,15 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), } grub_free (uuid_root); grub_free (uuid_prefix); + grub_free (prefdev); + grub_free (mods); return GRUB_ERR_NONE; fail: grub_free (uuid_root); grub_free (uuid_prefix); + grub_free (prefdev); for (i = 0; i < mods_loaded; i++) if (mods[i]) @@ -302,6 +310,8 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), mods[i]->fini = 0; grub_dl_unload (mods[i]); } + grub_free (mods); + return grub_errno; }