diff mbox

btrfs-progs: record_orphan_data_extent: Fix memory leak

Message ID 1494399482-15057-1-git-send-email-praveen@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Praveen K Pandey May 10, 2017, 6:58 a.m. UTC
The nodes of the list at btrfs_root->orphan_data_extents
are never freed causing memory to be leaked. This commit
fixes the bug by freeing the nodes on all the
btrfs_root->orphan_data_extents list.

Signed-off-by: Praveen K Pandey <praveen@linux.vnet.ibm.com>
---
 cmds-check.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
diff mbox

Patch

diff --git a/cmds-check.c b/cmds-check.c
index 0014bc2..cac94a8 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -9286,6 +9286,9 @@  static int check_extent_refs(struct btrfs_root *root,
 {
 	struct extent_record *rec;
 	struct cache_extent *cache;
+	struct btrfs_fs_info *fs_info;
+	struct btrfs_root *root_orphan_extent;
+	struct rb_node *rb_node;
 	int ret = 0;
 	int had_dups = 0;
 
@@ -9439,6 +9442,26 @@  static int check_extent_refs(struct btrfs_root *root,
 					   rec->start + rec->max_size - 1);
 		free(rec);
 	}
+	/*
+	 * Release memory of oprhan_data_extent
+	 * which allocated  while traversing in orphan_data_extents
+	 */
+
+	fs_info = root->fs_info;
+	rb_node = rb_first(&fs_info->fs_root_tree);
+	while (rb_node) {
+		root_orphan_extent = container_of(rb_node,
+						struct btrfs_root, rb_node);
+		free_orphan_data_extents(&root_orphan_extent->orphan_data_extents);
+		rb_node  = rb_next(rb_node);
+	}
+	free_orphan_data_extents(&fs_info->extent_root->orphan_data_extents);
+	free_orphan_data_extents(&fs_info->tree_root->orphan_data_extents);
+	free_orphan_data_extents(&fs_info->chunk_root->orphan_data_extents);
+	free_orphan_data_extents(&fs_info->dev_root->orphan_data_extents);
+	free_orphan_data_extents(&fs_info->csum_root->orphan_data_extents);
+	if (fs_info->quota_enabled)
+		free_orphan_data_extents(&fs_info->quota_root->orphan_data_extents);
 repair_abort:
 	if (repair) {
 		if (ret && ret != -EAGAIN) {