diff mbox series

[SRU,Xenial,1/1] Btrfs: fix extent map leak during fallocate error path

Message ID 20190403123857.1420-2-andrea.righi@canonical.com
State New
Headers show
Series btrfs: fallocate: fix memory leak | expand

Commit Message

Andrea Righi April 3, 2019, 12:38 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

BugLink: https://bugs.launchpad.net/bugs/1822579

If the call to btrfs_qgroup_reserve_data() failed, we were leaking an
extent map structure. The failure can happen either due to an -ENOMEM
condition or, when quotas are enabled, due to -EDQUOT for example.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
(backported from commit be2d253cc98244765323a7c94cc1ac5cd5a17072)
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
---
 fs/btrfs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Colin Ian King April 3, 2019, 12:48 p.m. UTC | #1
On 03/04/2019 13:38, Andrea Righi wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1822579
> 
> If the call to btrfs_qgroup_reserve_data() failed, we were leaking an
> extent map structure. The failure can happen either due to an -ENOMEM
> condition or, when quotas are enabled, due to -EDQUOT for example.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> Reviewed-by: David Sterba <dsterba@suse.com>
> (backported from commit be2d253cc98244765323a7c94cc1ac5cd5a17072)
> Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
> ---
>  fs/btrfs/file.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 751fcc6..743ad5e 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -2763,8 +2763,10 @@ static long btrfs_fallocate(struct file *file, int mode,
>  			}
>  			ret = btrfs_qgroup_reserve_data(inode, cur_offset,
>  					last_byte - cur_offset);
> -			if (ret < 0)
> +			if (ret < 0) {
> +				free_extent_map(em);
>  				break;
> +			}
>  		}
>  		free_extent_map(em);
>  		cur_offset = last_byte;
> 

Looks good to me; sane upstream fix and positive test results.

Acked-by: Colin Ian King <colin.king@canonical.com>
Thadeu Lima de Souza Cascardo April 3, 2019, 1:26 p.m. UTC | #2
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
diff mbox series

Patch

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 751fcc6..743ad5e 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2763,8 +2763,10 @@  static long btrfs_fallocate(struct file *file, int mode,
 			}
 			ret = btrfs_qgroup_reserve_data(inode, cur_offset,
 					last_byte - cur_offset);
-			if (ret < 0)
+			if (ret < 0) {
+				free_extent_map(em);
 				break;
+			}
 		}
 		free_extent_map(em);
 		cur_offset = last_byte;