[Debian-ha-commits] [ocfs2-tools] 31/58: fsck.ocfs2: the members of 'o2fsck_state' need to be freed at the end of main()

Valentin Vidic vvidic-guest at moszumanska.debian.org
Tue Jun 20 13:40:42 UTC 2017


This is an automated email from the git hooks/post-receive script.

vvidic-guest pushed a commit to branch upstream
in repository ocfs2-tools.

commit 89a53e3113b98bae46bbeeb4bdf7f235aead127e
Author: Jun Piao <piaojun at huawei.com>
Date:   Fri Oct 14 09:34:23 2016 +0800

    fsck.ocfs2: the members of 'o2fsck_state' need to be freed at the end of main()
    
    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>
    Reviewed-by: Joseph Qi <joseph.qi at huawei.com>
---
 fsck.ocfs2/fsck.c  | 20 +++++++++++++++++++-
 fsck.ocfs2/pass1.c |  6 ++----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/fsck.ocfs2/fsck.c b/fsck.ocfs2/fsck.c
index 70d855b..e5c7cfa 100644
--- a/fsck.ocfs2/fsck.c
+++ b/fsck.ocfs2/fsck.c
@@ -234,6 +234,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;
@@ -1139,7 +1155,9 @@ close:
 			/* 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 add3998..da11d22 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
@@ -146,8 +147,6 @@ static void update_inode_alloc(o2fsck_state *ost,
 
 			ost->ost_write_inode_alloc_asked = 1;
 			ost->ost_write_inode_alloc = !!yn;
-			if (!ost->ost_write_inode_alloc)
-				o2fsck_free_inode_allocs(ost);
 		}
 		break;
 	}
@@ -1447,8 +1446,6 @@ static void write_inode_alloc(o2fsck_state *ost)
 			com_err(whoami, ret, "while trying to write back slot "
 				"%d's inode allocator", i);
 	}
-
-	o2fsck_free_inode_allocs(ost);
 }
 
 errcode_t o2fsck_pass1(o2fsck_state *ost)
@@ -1566,6 +1563,7 @@ out_free:
 	o2fsck_add_resource_track(&ost->ost_rt, &rt);
 
 out:
+	o2fsck_free_inode_allocs(ost);
 	if (ost->ost_prog) {
 		tools_progress_stop(ost->ost_prog);
 		setlinebuf(stdout);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-ha/ocfs2-tools.git



More information about the Debian-HA-Commits mailing list