dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0413-normal-completion-Fix-leaking-of-memory-when-process.patch

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