diff mbox

[v2] Btrfs: fix memory leak when cloning root's node

Message ID 1351171819-2317-1-git-send-email-bo.li.liu@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Liu Bo Oct. 25, 2012, 1:30 p.m. UTC
After cloning root's node, we forgot to dec the src's ref
which can lead to a memory leak.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
v1->v2: fix a typo.

 fs/btrfs/ctree.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

Comments

Jan Schmidt Oct. 25, 2012, 1:42 p.m. UTC | #1
Chris: If you're not done yet, please put this one on top of the rc3-pile.
Otherwise this can wait for the next rc as well.

On Thu, October 25, 2012 at 15:30 (+0200), Liu Bo wrote:
> After cloning root's node, we forgot to dec the src's ref
> which can lead to a memory leak.
> 
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> ---
> v1->v2: fix a typo.
> 
>  fs/btrfs/ctree.c |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index eba44b0..cdfb4c4 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -1241,6 +1241,7 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
>  {
>  	struct tree_mod_elem *tm;
>  	struct extent_buffer *eb;
> +	struct extent_buffer *old;
>  	struct tree_mod_root *old_root = NULL;
>  	u64 old_generation = 0;
>  	u64 logical;
> @@ -1264,13 +1265,14 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
>  		btrfs_tree_read_unlock(root->node);
>  		free_extent_buffer(root->node);
>  		blocksize = btrfs_level_size(root, old_root->level);
> -		eb = read_tree_block(root, logical, blocksize, 0);
> -		if (!eb) {
> +		old = read_tree_block(root, logical, blocksize, 0);
> +		if (!old) {
>  			pr_warn("btrfs: failed to read tree block %llu from get_old_root\n",
>  				logical);
>  			WARN_ON(1);
>  		} else {
> -			eb = btrfs_clone_extent_buffer(eb);
> +			eb = btrfs_clone_extent_buffer(old);
> +			free_extent_buffer(old);
>  		}
>  	} else if (old_root) {
>  		btrfs_tree_read_unlock(root->node);

Reviewed-by: Jan Schmidt <list.btrfs@jan-o-sch.net>

Thanks :-)
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index eba44b0..cdfb4c4 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1241,6 +1241,7 @@  get_old_root(struct btrfs_root *root, u64 time_seq)
 {
 	struct tree_mod_elem *tm;
 	struct extent_buffer *eb;
+	struct extent_buffer *old;
 	struct tree_mod_root *old_root = NULL;
 	u64 old_generation = 0;
 	u64 logical;
@@ -1264,13 +1265,14 @@  get_old_root(struct btrfs_root *root, u64 time_seq)
 		btrfs_tree_read_unlock(root->node);
 		free_extent_buffer(root->node);
 		blocksize = btrfs_level_size(root, old_root->level);
-		eb = read_tree_block(root, logical, blocksize, 0);
-		if (!eb) {
+		old = read_tree_block(root, logical, blocksize, 0);
+		if (!old) {
 			pr_warn("btrfs: failed to read tree block %llu from get_old_root\n",
 				logical);
 			WARN_ON(1);
 		} else {
-			eb = btrfs_clone_extent_buffer(eb);
+			eb = btrfs_clone_extent_buffer(old);
+			free_extent_buffer(old);
 		}
 	} else if (old_root) {
 		btrfs_tree_read_unlock(root->node);