[Ocfs2-tools-devel] [PATCH v2] fsck.ocfs2: the members of 'o2fsck_state' need to be freed at the end of main()

piaojun piaojun at huawei.com
Sun Sep 25 00:08:33 PDT 2016


The allocation for the members of 'o2fsck_state' by o2fsck_state_init()
need to be freed at last in case of memory leak.

Signed-off-by: Jun Piao <piaojun at huawei.com>
---
 fsck.ocfs2/fsck.c  | 20 +++++++++++++++++++-
 fsck.ocfs2/pass1.c |  1 +
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/fsck.ocfs2/fsck.c b/fsck.ocfs2/fsck.c
index dc5209d..481a7e7 100644
--- a/fsck.ocfs2/fsck.c
+++ b/fsck.ocfs2/fsck.c
@@ -232,6 +232,22 @@ errcode_t o2fsck_state_reinit(ocfs2_filesys *fs, o2fsck_state *ost)
 	return 0;
 }
 
+static void o2fsck_state_release(o2fsck_state *ost)
+{
+	if (ost->ost_dir_inodes)
+		ocfs2_bitmap_free(&ost->ost_dir_inodes);
+	if (ost->ost_reg_inodes)
+		ocfs2_bitmap_free(&ost->ost_reg_inodes);
+	if (ost->ost_allocated_clusters)
+		ocfs2_bitmap_free(&ost->ost_allocated_clusters);
+	if (ost->ost_duplicate_clusters)
+		ocfs2_bitmap_free(&ost->ost_duplicate_clusters);
+	if (ost->ost_icount_in_inodes)
+		o2fsck_icount_free(ost->ost_icount_in_inodes);
+	if (ost->ost_icount_refs)
+		o2fsck_icount_free(ost->ost_icount_refs);
+}
+
 static errcode_t check_superblock(o2fsck_state *ost)
 {
 	struct ocfs2_dinode *di = ost->ost_fs->fs_super;
@@ -1102,7 +1118,9 @@ close:
 		com_err(whoami, ret, "while closing file \"%s\"", filename);
 		/* XXX I wonder about this error.. */
 		fsck_mask |= FSCK_ERROR;
-	} 
+	}
+
+	o2fsck_state_release(ost);
 
 out:
 	return fsck_mask;
diff --git a/fsck.ocfs2/pass1.c b/fsck.ocfs2/pass1.c
index c076e28..530bd8d 100644
--- a/fsck.ocfs2/pass1.c
+++ b/fsck.ocfs2/pass1.c
@@ -83,6 +83,7 @@ void o2fsck_free_inode_allocs(o2fsck_state *ost)
 
 	for (i = 0; i < OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_max_slots; i++)
 		ocfs2_free_cached_inode(ost->ost_fs, ost->ost_inode_allocs[i]);
+	ocfs2_free(&ost->ost_inode_allocs);
 }
 
 /* update our in memory images of the inode chain alloc bitmaps.  these
-- 
1.8.4.3




More information about the Ocfs2-tools-devel mailing list