diff mbox series

[RFC,v2,50/51] e2fsck: fix to free icache leak

Message ID 1592494074-28991-51-git-send-email-wangshilong1991@gmail.com
State Superseded
Headers show
Series introduce parallel fsck to e2fsck pass1 | expand

Commit Message

Wang Shilong June 18, 2020, 3:27 p.m. UTC
From: Wang Shilong <wshilong@ddn.com>

Signed-off-by: Wang Shilong <wshilong@ddn.com>
---
 e2fsck/pass1.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 52af4f13..990e4b04 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -2513,6 +2513,7 @@  static errcode_t e2fsck_pass1_copy_fs(ext2_filsys dest, e2fsck_t src_context,
 	memcpy(dest, src, sizeof(struct struct_ext2_filsys));
 	dest->inode_map = NULL;
 	dest->block_map = NULL;
+	dest->icache = NULL;
 
 	/*
 	 * PASS1_COPY_FS_BITMAP might return directly from this function,
@@ -2521,13 +2522,6 @@  static errcode_t e2fsck_pass1_copy_fs(ext2_filsys dest, e2fsck_t src_context,
 	PASS1_COPY_FS_BITMAP(dest, src, inode_map);
 	PASS1_COPY_FS_BITMAP(dest, src, block_map);
 
-	/* icache will be rebuilt if needed, so do not copy from @src */
-	if (src->icache) {
-		ext2fs_free_inode_cache(src->icache);
-		src->icache = NULL;
-	}
-	dest->icache = NULL;
-
 	if (src->dblist) {
 		retval = ext2fs_copy_dblist(src->dblist, &dest->dblist);
 		if (retval)
@@ -2593,6 +2587,7 @@  static int _e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src)
 	ext2_dblist dblist;
 	int flags;
 	e2fsck_t dest_ctx = dest->priv_data;
+	struct ext2_inode_cache *icache = dest->icache;
 
 	dest_io = dest->io;
 	dest_image_io = dest->image_io;
@@ -2610,6 +2605,7 @@  static int _e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src)
 	dest->dblist = dblist;
 	dest->priv_data = dest_ctx;
 	dest->flags = src->flags | flags;
+	dest->icache = icache;
 	if (!(src->flags & EXT2_FLAG_VALID) || !(flags & EXT2_FLAG_VALID))
 		ext2fs_unmark_valid(dest);
 	/*
@@ -2654,17 +2650,15 @@  static int e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src)
 
 	retval = _e2fsck_pass1_merge_fs(dest, src);
 
-	if (src->inode_map)
-		ext2fs_free_generic_bmap(src->inode_map);
-	if (src->block_map)
-		ext2fs_free_generic_bmap(src->block_map);
-
-	/* icache will be rebuilt if needed, so do not copy from @src */
 	if (src->icache) {
 		ext2fs_free_inode_cache(src->icache);
 		src->icache = NULL;
 	}
-	dest->icache = NULL;
+
+	if (src->inode_map)
+		ext2fs_free_generic_bmap(src->inode_map);
+	if (src->block_map)
+		ext2fs_free_generic_bmap(src->block_map);
 
 	if (src->dblist) {
 		ext2fs_free_dblist(src->dblist);