Btrfs-progs: Add missing free() against fs_info->super_copy
PATCH 1/1 Btrfs-progs: Add missing free() against fs_info->super_copy
There was a missing free() call against fs_info->super_copy in several places:
1) close_ctree()
2) open_ctree_broken() on failure
3) __open_ctree_fd() on failure
Filipe David Borba Manana (1):
Btrfs-progs: Add missing free() against fs_info->super_copy
btrfs-find-root.c | 5 +++-- disk-io.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/1 Btrfs-progs: Add missing free() against fs_info->super_copy
There was a missing free() call against fs_info->super_copy in several places:
1) close_ctree()
2) open_ctree_broken() on failure
3) __open_ctree_fd() on failure
--- btrfs-find-root.c | 5 +++-- disk-io.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-)
btrfs-find-root.c +3 -2
@@ -94,7 +94,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device)struct btrfs_root *chunk_root =malloc (sizeof (struct btrfs_root ));struct btrfs_root *dev_root =malloc (sizeof (struct btrfs_root ));struct btrfs_root *csum_root =malloc (sizeof (struct btrfs_root )); -struct btrfs_fs_info *fs_info =malloc (sizeof (*fs_info)); +struct btrfs_fs_info *fs_info =calloc (1 ,sizeof (*fs_info));int ret;struct btrfs_super_block *disk_super;struct btrfs_fs_devices *fs_devices =NULL ;
@@ -115,7 +115,6 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device) goto out; } -memset (fs_info,0 ,sizeof (*fs_info)); fs_info->super_copy =calloc (1 ,BTRFS_SUPER_INFO_SIZE ); fs_info->tree_root = tree_root; fs_info->extent_root = extent_root;
@@ -228,6 +227,8 @@ out:free (chunk_root);free (dev_root);free (csum_root); +if (fs_info) +free (fs_info->super_copy);free (fs_info);return NULL ; }
disk-io.c +4 -2
@@ -812,7 +812,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,struct btrfs_root *chunk_root =malloc (sizeof (struct btrfs_root ));struct btrfs_root *dev_root =malloc (sizeof (struct btrfs_root ));struct btrfs_root *csum_root =malloc (sizeof (struct btrfs_root )); -struct btrfs_fs_info *fs_info =malloc (sizeof (*fs_info)); +struct btrfs_fs_info *fs_info =calloc (1 ,sizeof (*fs_info));int ret;struct btrfs_super_block *disk_super;struct btrfs_fs_devices *fs_devices =NULL ;
@@ -840,7 +840,6 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, goto out; } -memset (fs_info,0 ,sizeof (*fs_info)); fs_info->super_copy =calloc (1 ,BTRFS_SUPER_INFO_SIZE ); fs_info->tree_root = tree_root; fs_info->extent_root = extent_root;
@@ -1039,6 +1038,8 @@ out:free (chunk_root);free (dev_root);free (csum_root); +if (fs_info) +free (fs_info->super_copy);free (fs_info);return NULL ; }
@@ -1347,6 +1348,7 @@ int close_ctree(struct btrfs_root *root)free (fs_info->chunk_root);free (fs_info->dev_root);free (fs_info->csum_root); +free (fs_info->super_copy);free (fs_info);return 0 ;
Signature · 1 line
1.7.9.5
Hi,
please don't forget to mention what changed in a revised version
btrfs-find-root.c out: · line 231
Quoted 6 lines · Filipe David Borba Manana
btrfs-find-root.c +2
-0@@ -228,6 +227,8 @@ out:free (chunk_root);free (dev_root);free (csum_root); +if (fs_info) +free (fs_info->super_copy);
free accepts NULL pointers and does nothing, so it's fine to do it as in the first version.
Review out: · line 233
Quoted 2 lines
(quoted diff) +0
-0free(fs_info); return NULL;
otherwise ok. Thanks.
david
Quoted 3 lines · David Sterba
Hi,
please don't forget to mention what changed in a revised version
Yeah, sorry, it was my first usage of git send-email (as described in the wiki).
Quoted 11 lines · Filipe David Borba Manana
btrfs-find-root.c out: · line 231
Quoted 6 lines
btrfs-find-root.c +2
-0@@ -228,6 +227,8 @@ out:free (chunk_root);free (dev_root);free (csum_root); +if (fs_info) +free (fs_info->super_copy);free accepts NULL pointers and does nothing, so it's fine to do it as in the first version.
Right. Just thought it was better to check if the calloc() for fs_info succeeded before derreferencing it for free'ing its super_copy member (the function's code doesn't check if any of the malloc() / calloc() calls returned non-NULL, so it wouldn't be inconsistent with the existing code)
Quoted 5 lines
Review out: · line 233
Quoted 3 lines
(quoted diff) +0
-0free(fs_info); return NULL;otherwise ok. Thanks.
Thanks for review and advise.
Do you need more action from my side?
Quoted 2 lines
david
--
Filipe David Manana,
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves. That's why all progress depends on unreasonable men."
Quoted 5 lines · Filipe David Manana
Right. Just thought it was better to check if the
calloc()forfs_infosucceeded before derreferencing it for free'ing itssuper_copymember (the function's code doesn't check if any of themalloc()/calloc()calls returned non-NULL, so it wouldn't be inconsistent with the existing code)
Sorry, I've read it too quickly, the check has to be there of course.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
free(fs_info); return NULL;otherwise ok. Thanks.
Thanks for review and advise.
Do you need more action from my side?
No.
david