[Ocfs2-tools-devel] [PATCH 2/8] Fix a memory leak problem in freefs.c

piaojun piaojun at huawei.com
Wed Mar 18 00:38:47 PDT 2015


In ocfs2_freefs(), fs->fs_inode_allocs and fs->fs_eb_allocs are two level
pointer, so every element in array should be freed through
ocfs2_free_fs_inode_allocs(). Besides fs->fs_inode_allocs, fs->fs_eb_allocs
and fs->ost should be freed after use.

Signed-off-by: Jun Piao <piaojun at huawei.com>
Reviewed-by: Alex Chen <alex.chen at huawei.com>

---
 libocfs2/freefs.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/libocfs2/freefs.c b/libocfs2/freefs.c
index ab8a8ea..1fa9424 100644
--- a/libocfs2/freefs.c
+++ b/libocfs2/freefs.c
@@ -32,18 +32,50 @@

 #include "ocfs2/ocfs2.h"

+void ocfs2_free_fs_inode_allocs(ocfs2_filesys *fs)
+{
+	uint16_t i;
+	uint16_t max_slots = 0;
+	struct ocfs2_super_block *osb = OCFS2_RAW_SB(fs->fs_super);
+	if (!osb)
+		return;
+	max_slots = osb->s_max_slots;
+	ocfs2_free_cached_inode(fs, fs->fs_system_inode_alloc);
+
+	if (fs->fs_inode_allocs) {
+		for (i = 0; i < max_slots; i++) {
+			ocfs2_free_cached_inode(fs, fs->fs_inode_allocs[i]);
+		}
+	}
+
+ 	if (fs->fs_eb_allocs) {
+		for (i = 0; i < max_slots; i++) {
+			ocfs2_free_cached_inode(fs, fs->fs_eb_allocs[i]);
+		}
+	}
+
+	return;
+}

 void ocfs2_freefs(ocfs2_filesys *fs)
 {
 	if (!fs)
 		abort();

+	ocfs2_free_fs_inode_allocs(fs);
+
 	if (fs->fs_orig_super)
 		ocfs2_free(&fs->fs_orig_super);
 	if (fs->fs_super)
 		ocfs2_free(&fs->fs_super);
 	if (fs->fs_devname)
 		ocfs2_free(&fs->fs_devname);
+	if (fs->fs_inode_allocs)
+		ocfs2_free(&fs->fs_inode_allocs);
+	if (fs->fs_eb_allocs)
+		ocfs2_free(&fs->fs_eb_allocs);
+	if (fs->ost)
+		ocfs2_free(&fs->ost);
 	if (fs->fs_io)
 		io_close(fs->fs_io);

-- 1.8.4.3




More information about the Ocfs2-tools-devel mailing list