1From 9213575b7a95b514bce80be5964a28d407d7d56d Mon Sep 17 00:00:00 2001 2From: Darren Kenny <darren.kenny@oracle.com> 3Date: Fri, 4 Dec 2020 18:56:48 +0000 4Subject: [PATCH] normal/completion: Fix leaking of memory when processing a 5 completion 6 7It is possible for the code to reach the end of the function without 8freeing the memory allocated to argv and argc still to be 0. 9 10We should always call grub_free(argv). The grub_free() will handle 11a NULL argument correctly if it reaches that code without the memory 12being allocated. 13 14Fixes: CID 96672 15 16Signed-off-by: Darren Kenny <darren.kenny@oracle.com> 17Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> 18Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com> 19--- 20 grub-core/normal/completion.c | 10 ++++------ 21 1 file changed, 4 insertions(+), 6 deletions(-) 22 23diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c 24index 5961028..46e473c 100644 25--- a/grub-core/normal/completion.c 26+++ b/grub-core/normal/completion.c 27@@ -400,8 +400,8 @@ char * 28 grub_normal_do_completion (char *buf, int *restore, 29 void (*hook) (const char *, grub_completion_type_t, int)) 30 { 31- int argc; 32- char **argv; 33+ int argc = 0; 34+ char **argv = NULL; 35 36 /* Initialize variables. */ 37 match = 0; 38@@ -516,10 +516,8 @@ grub_normal_do_completion (char *buf, int *restore, 39 40 fail: 41 if (argc != 0) 42- { 43- grub_free (argv[0]); 44- grub_free (argv); 45- } 46+ grub_free (argv[0]); 47+ grub_free (argv); 48 grub_free (match); 49 grub_errno = GRUB_ERR_NONE; 50 51-- 522.14.2 53 54