Skip to contentSkip to conversation

Btrfs: fix extent map leak during fallocate error path

PATCH In review [email protected] 3 participants 3 messages Apr 4, 2017 – Apr 18, 2017 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fix extent map leak during fallocate error path

From: Filipe Manana <[email protected]>

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.

---
 fs/btrfs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/file.c +3 -1
index 48dfb8e..56304c4 100644
@@ -2856,8 +2856,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;
+			}
 		} else {
 			/*
 			 * Do not need to reserve unwritten extent for this
Signature · 1 line
2.7.0.rc3
Reviewed-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 6 lines · On Tue, Apr 04, 2017 at 03:20:36AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

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.

Thanks,

-liubo

Quoted 28 lines
---
 fs/btrfs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/file.c +3 -1
index 48dfb8e..56304c4 100644
@@ -2856,8 +2856,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;
+			}
 		} else {
 			/*
 			 * Do not need to reserve unwritten extent for this
Signature · 6 lines
2.7.0.rc3

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html