0076-normal-completion-Fix-leaking-of-memory-when-process.patch 1.5 KB

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