fs/affs: Fix memory leaks in grub_affs_create_node()

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>
This commit is contained in:
t.feng authored and Daniel Kiper committed 2022-12-07 23:38:25 +01:00
1 parent 77afd25f80
commit 022365aeaa
1 file changed
+2 -7
+2 -7
View File
@@ -321,7 +321,6 @@ static int
grub_affs_create_node (grub_fshelp_node_t dir, grub_affs_create_node (grub_fshelp_node_t dir,
grub_fshelp_iterate_dir_hook_t hook, void *hook_data, grub_fshelp_iterate_dir_hook_t hook, void *hook_data,
struct grub_fshelp_node **node, struct grub_fshelp_node **node,
grub_uint32_t **hashtable,
grub_uint32_t block, const struct grub_affs_file *fil) grub_uint32_t block, const struct grub_affs_file *fil)
{ {
struct grub_affs_data *data = dir->data; 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)); *node = grub_zalloc (sizeof (**node));
if (!*node) if (!*node)
{
grub_free (*hashtable);
return 1; return 1;
}
(*node)->data = data; (*node)->data = data;
(*node)->block = block; (*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)) if (hook ((char *) name_u8, type, *node, hook_data))
{ {
grub_free (*hashtable);
*node = 0; *node = 0;
return 1; return 1;
} }
@@ -460,11 +455,11 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
if (grub_errno) if (grub_errno)
goto fail; goto fail;
if (grub_affs_create_node (dir, hook, hook_data, &node, &hashtable, if (grub_affs_create_node (dir, hook, hook_data, &node, next, &file))
next, &file))
{ {
/* Node has been replaced in function. */ /* Node has been replaced in function. */
grub_free (orig_node); grub_free (orig_node);
grub_free (hashtable);
return 1; return 1;
} }