2009-01-17 15:04:09

by Qinghuang Feng

[permalink] [raw]
Subject: [PATCH] Btrfs: fix bug in open_ctree()

a bug in open_ctree:

struct btrfs_root *open_ctree(..)
{
....
if (!extent_root || !tree_root || !fs_info ||
!chunk_root || !dev_root || !csum_root) {
err = -ENOMEM;
goto fail;
//When code flow goes to "fail", fs_info may be NULL or uninitialized.
}
....

fail:
btrfs_close_devices(fs_info->fs_devices);// !
btrfs_mapping_tree_free(&fs_info->mapping_tree);// !

kfree(extent_root);
kfree(tree_root);
bdi_destroy(&fs_info->bdi);// !
...
)

Signed-off-by: Qinghuang Feng <[email protected]>
---
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 81a3138..f860087 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1828,13 +1828,14 @@ fail_sb_buffer:
fail_iput:
invalidate_inode_pages2(fs_info->btree_inode->i_mapping);
iput(fs_info->btree_inode);
-fail:
+
btrfs_close_devices(fs_info->fs_devices);
btrfs_mapping_tree_free(&fs_info->mapping_tree);
+ bdi_destroy(&fs_info->bdi);

+fail:
kfree(extent_root);
kfree(tree_root);
- bdi_destroy(&fs_info->bdi);
kfree(fs_info);
kfree(chunk_root);
kfree(dev_root);


2009-01-17 21:30:08

by Chris Mason

[permalink] [raw]
Subject: Re: [PATCH] Btrfs: fix bug in open_ctree()

On Sat, 2009-01-17 at 23:03 +0800, Qinghuang Feng wrote:
> a bug in open_ctree:
>

Thanks, this looks good.

-chris