linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: record_orphan_data_extent: Fix memory leak
@ 2017-05-10  6:58 Praveen K Pandey
  0 siblings, 0 replies; only message in thread
From: Praveen K Pandey @ 2017-05-10  6:58 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, Praveen K Pandey

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 --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) {
-- 
2.9.3


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-10  6:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-10  6:58 [PATCH] btrfs-progs: record_orphan_data_extent: Fix memory leak Praveen K Pandey

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).