|
|
468bd4 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
468bd4 |
From: Darren Kenny <darren.kenny@oracle.com>
|
|
|
468bd4 |
Date: Fri, 4 Dec 2020 18:56:48 +0000
|
|
|
468bd4 |
Subject: [PATCH] normal/completion: Fix leaking of memory when processing a
|
|
|
468bd4 |
completion
|
|
|
468bd4 |
|
|
|
468bd4 |
It is possible for the code to reach the end of the function without
|
|
|
468bd4 |
freeing the memory allocated to argv and argc still to be 0.
|
|
|
468bd4 |
|
|
|
468bd4 |
We should always call grub_free(argv). The grub_free() will handle
|
|
|
468bd4 |
a NULL argument correctly if it reaches that code without the memory
|
|
|
468bd4 |
being allocated.
|
|
|
468bd4 |
|
|
|
468bd4 |
Fixes: CID 96672
|
|
|
468bd4 |
|
|
|
468bd4 |
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
|
|
|
468bd4 |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
468bd4 |
---
|
|
|
468bd4 |
grub-core/normal/completion.c | 10 ++++------
|
|
|
468bd4 |
1 file changed, 4 insertions(+), 6 deletions(-)
|
|
|
468bd4 |
|
|
|
468bd4 |
diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c
|
|
|
f6e916 |
index 93aa0d8ed..5036bcf2d 100644
|
|
|
468bd4 |
--- a/grub-core/normal/completion.c
|
|
|
468bd4 |
+++ b/grub-core/normal/completion.c
|
|
|
468bd4 |
@@ -401,8 +401,8 @@ char *
|
|
|
468bd4 |
grub_normal_do_completion (char *buf, int *restore,
|
|
|
468bd4 |
void (*hook) (const char *, grub_completion_type_t, int))
|
|
|
468bd4 |
{
|
|
|
468bd4 |
- int argc;
|
|
|
468bd4 |
- char **argv;
|
|
|
468bd4 |
+ int argc = 0;
|
|
|
468bd4 |
+ char **argv = NULL;
|
|
|
468bd4 |
|
|
|
468bd4 |
/* Initialize variables. */
|
|
|
468bd4 |
match = 0;
|
|
|
468bd4 |
@@ -517,10 +517,8 @@ grub_normal_do_completion (char *buf, int *restore,
|
|
|
468bd4 |
|
|
|
468bd4 |
fail:
|
|
|
468bd4 |
if (argc != 0)
|
|
|
468bd4 |
- {
|
|
|
468bd4 |
- grub_free (argv[0]);
|
|
|
468bd4 |
- grub_free (argv);
|
|
|
468bd4 |
- }
|
|
|
468bd4 |
+ grub_free (argv[0]);
|
|
|
468bd4 |
+ grub_free (argv);
|
|
|
468bd4 |
grub_free (match);
|
|
|
468bd4 |
grub_errno = GRUB_ERR_NONE;
|
|
|
468bd4 |
|