[Ocfs2-tools-devel] [PATCH] libocfs2: Fix a memory leak problem

piaojun piaojun at huawei.com
Sun Apr 26 17:48:03 PDT 2015


1. In ocfs2_initialize_dlm()->ocfs2_fill_cluster_desc()->ocfs2_userspace_stack(),
if 'osb->s_feature_incompat' is set with
OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK, ocfs2_userspace_stack() will
return zero and then we will allocate memory for 'desc->c_stack' and
'desc->c_cluster'. But the memory is not freed after use.

2. In ocfs2_shutdown_dlm(), the same problem happens again.

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

---
 libocfs2/dlm.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libocfs2/dlm.c b/libocfs2/dlm.c
index 8c4a3ae..0840d84 100644
--- a/libocfs2/dlm.c
+++ b/libocfs2/dlm.c
@@ -299,6 +299,13 @@ errcode_t ocfs2_initialize_dlm(ocfs2_filesys *fs, const char *service)
 		o2dlm_destroy(dlm_ctxt);

 bail:
+	if (cluster.c_stack) {
+		ocfs2_free(&cluster.c_stack);
+	}
+
+	if (cluster.c_cluster) {
+		ocfs2_free(&cluster.c_cluster);
+	}
 	return ret;
 }

@@ -327,6 +334,13 @@ errcode_t ocfs2_shutdown_dlm(ocfs2_filesys *fs, const char *service)
 	ret = o2cb_group_leave(&cluster, &desc);

 bail:
+	if (cluster.c_stack) {
+		ocfs2_free(&cluster.c_stack);
+	}
+
+	if (cluster.c_cluster) {
+		ocfs2_free(&cluster.c_cluster);
+	}
 	return ret;
 }

-- 1.8.4.3




More information about the Ocfs2-tools-devel mailing list