]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
normal/completion: Fix leaking of memory when processing a completion
authorDarren Kenny <darren.kenny@oracle.com>
Fri, 4 Dec 2020 18:56:48 +0000 (18:56 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Mar 2021 14:54:17 +0000 (15:54 +0100)
It is possible for the code to reach the end of the function without
freeing the memory allocated to argv and argc still to be 0.

We should always call grub_free(argv). The grub_free() will handle
a NULL argument correctly if it reaches that code without the memory
being allocated.

Fixes: CID 96672
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/normal/completion.c

index c07100a8de3e4337844a57ad6b085174ff10ef4c..18cadfa8543054741475ac9a684fe50b1f2bd0bf 100644 (file)
@@ -401,8 +401,8 @@ char *
 grub_normal_do_completion (char *buf, int *restore,
                           void (*hook) (const char *, grub_completion_type_t, int))
 {
-  int argc;
-  char **argv;
+  int argc = 0;
+  char **argv = NULL;
 
   /* Initialize variables.  */
   match = 0;
@@ -517,10 +517,8 @@ grub_normal_do_completion (char *buf, int *restore,
 
  fail:
   if (argc != 0)
-    {
-      grub_free (argv[0]);
-      grub_free (argv);
-    }
+    grub_free (argv[0]);
+  grub_free (argv);
   grub_free (match);
   grub_errno = GRUB_ERR_NONE;