]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
fs/affs: Fix memory leaks in grub_affs_create_node()
authort.feng <fengtao40@huawei.com>
Tue, 29 Nov 2022 09:14:07 +0000 (17:14 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Wed, 7 Dec 2022 22:38:25 +0000 (23:38 +0100)
The hashtable is not freed if GRUB_AFFS_FILETYPE_HARDLINK and
grub_disk_read() failed. If grub_affs_create_node() returns non-zero
the hashtable should be freed too.

By the way, the hashtable argument is unused in grub_affs_create_node().
So, we can remove the argument and free it in grub_affs_iterate_dir().
It allocates the memory and it should be responsible for releasing it.

This is why commit ebf32bc4e9 (fs/affs: Fix resource leaks) missed
this memory leak.

Fixes: ebf32bc4e9 (fs/affs: Fix resource leaks)
Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/fs/affs.c

index 631d3d58a7c37f027aa138a86f3551f88c537c4a..ed606b3f15a1c0fdef44432cf56ecb21473a3b15 100644 (file)
@@ -321,7 +321,6 @@ static int
 grub_affs_create_node (grub_fshelp_node_t dir,
                       grub_fshelp_iterate_dir_hook_t hook, void *hook_data,
                       struct grub_fshelp_node **node,
-                      grub_uint32_t **hashtable,
                       grub_uint32_t block, const struct grub_affs_file *fil)
 {
   struct grub_affs_data *data = dir->data;
@@ -332,10 +331,7 @@ grub_affs_create_node (grub_fshelp_node_t dir,
 
   *node = grub_zalloc (sizeof (**node));
   if (!*node)
-    {
-      grub_free (*hashtable);
-      return 1;
-    }
+    return 1;
 
   (*node)->data = data;
   (*node)->block = block;
@@ -395,7 +391,6 @@ grub_affs_create_node (grub_fshelp_node_t dir,
 
   if (hook ((char *) name_u8, type, *node, hook_data))
     {
-      grub_free (*hashtable);
       *node = 0;
       return 1;
     }
@@ -460,11 +455,11 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
          if (grub_errno)
            goto fail;
 
-         if (grub_affs_create_node (dir, hook, hook_data, &node, &hashtable,
-                                    next, &file))
+         if (grub_affs_create_node (dir, hook, hook_data, &node, next, &file))
            {
              /* Node has been replaced in function. */
              grub_free (orig_node);
+             grub_free (hashtable);
              return 1;
            }