]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/file: Do not leak device_name on error in grub_file_open()
authorDaniel Axtens <dja@axtens.net>
Thu, 24 Jun 2021 16:19:05 +0000 (02:19 +1000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 7 Jun 2022 14:39:32 +0000 (16:39 +0200)
If we have an error in grub_file_open() before we free device_name, we
will leak it.

Free device_name in the error path and null out the pointer in the good
path once we free it there.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/file.c

index df24c1fd44916641730db89228118025fc579616..8d48fd50dc6bea5640d681bc08c4c1869bd71172 100644 (file)
@@ -79,6 +79,7 @@ grub_file_open (const char *name, enum grub_file_type type)
 
   device = grub_device_open (device_name);
   grub_free (device_name);
+  device_name = NULL;
   if (! device)
     goto fail;
 
@@ -131,6 +132,7 @@ grub_file_open (const char *name, enum grub_file_type type)
   return file;
 
  fail:
+  grub_free (device_name);
   if (device)
     grub_device_close (device);