Fix several memory leaks.

* grub-core/fs/btrfs.c (grub_btrfs_dir): Fix memory leak.
	* grub-core/fs/cpio.c (grub_cpio_find_file): Likewise.
	(grub_cpio_dir): Likewise.
	* grub-core/fs/fat.c (grub_fat_label): Likewise.
	* grub-core/fs/jfs.c (grub_jfs_label): Likewise.
	* grub-core/fs/romfs.c (grub_romfs_close): Likewise.
	(grub_romfs_label): Likewise.
	* grub-core/fs/squash4.c (squash_mount): Use zalloc for safety.
	(squash_unmount): New function.
	(grub_squash_dir): Fix memory leak.
	(grub_squash_open): Likewise.
	(grub_squash_read): Likewise.
	(grub_squash_mtime): Likewise.
	* grub-core/fs/xfs.c (grub_xfs_open): Likewise.
	* grub-core/fs/zfs/zfs.c (check_pool_label): Likewise.
	* util/grub-fstest.c (fstest): Likewise.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-11-09 15:01:58 +01:00
parent 57b0125004
commit 8a5a3a5b5a
10 changed files with 84 additions and 22 deletions

View file

@ -287,7 +287,7 @@ squash_mount (grub_disk_t disk)
if (err)
return NULL;
data = grub_malloc (sizeof (*data));
data = grub_zalloc (sizeof (*data));
if (!data)
return NULL;
data->sb = sb;
@ -418,6 +418,15 @@ make_root_node (struct grub_squash_data *data, struct grub_fshelp_node *root)
grub_cpu_to_le16 (data->sb.root_ino_offset));
}
static void
squash_unmount (struct grub_squash_data *data)
{
grub_free (data->ino.cumulated_block_sizes);
grub_free (data->ino.block_sizes);
grub_free (data);
}
static grub_err_t
grub_squash_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename,
@ -436,6 +445,7 @@ grub_squash_dir (grub_device_t device, const char *path,
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
info.mtimeset = 1;
info.mtime = grub_le_to_cpu32 (node->ino.mtime);
grub_free (node);
return hook (filename, &info);
}
@ -457,7 +467,7 @@ grub_squash_dir (grub_device_t device, const char *path,
if (!grub_errno)
grub_squash_iterate_dir (fdiro, iterate);
grub_free (data);
squash_unmount (data);
return grub_errno;
}
@ -482,7 +492,7 @@ grub_squash_open (struct grub_file *file, const char *name)
grub_squash_read_symlink, GRUB_FSHELP_REG);
if (grub_errno)
{
grub_free (data);
squash_unmount (data);
return grub_errno;
}
@ -499,6 +509,8 @@ grub_squash_open (struct grub_file *file, const char *name)
else
file->size = grub_le_to_cpu32 (fdiro->ino.file.size);
grub_free (fdiro);
return GRUB_ERR_NONE;
}
@ -664,7 +676,7 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len)
static grub_err_t
grub_squash_close (grub_file_t file)
{
grub_free (file->data);
squash_unmount (file->data);
return GRUB_ERR_NONE;
}
@ -677,7 +689,7 @@ grub_squash_mtime (grub_device_t dev, grub_int32_t *tm)
if (! data)
return grub_errno;
*tm = grub_le_to_cpu32 (data->sb.creation_time);
grub_free (data);
squash_unmount (data);
return GRUB_ERR_NONE;
}