linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix dip leak
@ 2011-03-09 16:46 Daniel J Blueman
  2011-03-10  2:54 ` Miao Xie
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel J Blueman @ 2011-03-09 16:46 UTC (permalink / raw)
  To: miaox, Josef Bacik, Chris Mason, Linux Btrfs; +Cc: Ito

2010/11/22 Miao Xie <miaox@cn.fujitsu.com>:
> bio_endio() will free dip and dip->csums, so dip and dip->csums twice=
 will
> be freed twice. Fix it.
>
> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
> ---
> =A0fs/btrfs/inode.c | =A0 =A09 +++------
> =A01 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 558cac2..5a5edc7 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -5731,7 +5731,7 @@ static void btrfs_submit_direct(int rw, struct =
bio *bio, struct inode *inode,
>
> =A0 =A0 =A0 =A0ret =3D btrfs_bio_wq_end_io(root->fs_info, bio, 0);
> =A0 =A0 =A0 =A0if (ret)
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_err;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto free_ordered;
>
> =A0 =A0 =A0 =A0if (write && !skip_sum) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D btrfs_wq_submit_bio(BTRFS_I(in=
ode)->root->fs_info,
> @@ -5740,7 +5740,7 @@ static void btrfs_submit_direct(int rw, struct =
bio *bio, struct inode *inode,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _=
_btrfs_submit_bio_start_direct_io,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _=
_btrfs_submit_bio_done);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (ret)
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_err;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto free_ordered;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return;
> =A0 =A0 =A0 =A0} else if (!skip_sum)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0btrfs_lookup_bio_sums_dio(root, inode,=
 bio,
> @@ -5748,11 +5748,8 @@ static void btrfs_submit_direct(int rw, struct=
 bio *bio, struct inode *inode,
>
> =A0 =A0 =A0 =A0ret =3D btrfs_map_bio(root, rw, bio, 0, 1);
> =A0 =A0 =A0 =A0if (ret)
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_err;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto free_ordered;
> =A0 =A0 =A0 =A0return;
> -out_err:
> - =A0 =A0 =A0 kfree(dip->csums);
> - =A0 =A0 =A0 kfree(dip);
> =A0free_ordered:
> =A0 =A0 =A0 =A0/*
> =A0 =A0 =A0 =A0 * If this is a write, we need to clean up the reserve=
d space and kill

The previous patch is broken and leaks dip when dip->csums allocation
fails; bio->bi_end_io isn't set at the point where the free_ordered
branch is consequently taken, thus bio_endio doesn't call the function
which would free it in the normal case. Fix.

Signed-off-by: Daniel J Blueman <daniel.blueman@gmail.com>

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 0efdb65..53f4c8e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6056,6 +6056,7 @@ static void btrfs_submit_direct(int rw, struct
bio *bio, struct inode *inode,
 	if (!skip_sum) {
 		dip->csums =3D kmalloc(sizeof(u32) * bio->bi_vcnt, GFP_NOFS);
 		if (!dip->csums) {
+			kfree(dip);
 			ret =3D -ENOMEM;
 			goto free_ordered;
 		}
--=20
Daniel J Blueman
--
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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-03-10  2:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-09 16:46 [PATCH] btrfs: fix dip leak Daniel J Blueman
2011-03-10  2:54 ` Miao Xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).