[Ocfs2-tools-devel] [PATCH] Fix memory leak problems in o2cb_config.c

piaojun piaojun at huawei.com
Tue Mar 3 04:10:15 PST 2015


Two memory leak problems were found in o2cb_config.c. The details of the
problems are described below:

1. In o2cb_cluster_fill_node(), the memory allocated for 'name' should be
   freed before the function return.

2. In o2cb_config_fill_cluster(), the 'count' should be freed after use.

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

---
 o2cb_ctl/o2cb_config.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/o2cb_ctl/o2cb_config.c b/o2cb_ctl/o2cb_config.c
index 997dab3..f79ed5c 100644
--- a/o2cb_ctl/o2cb_config.c
+++ b/o2cb_ctl/o2cb_config.c
@@ -127,8 +127,10 @@ static gint o2cb_cluster_fill_node(O2CBCluster *cluster,
     /* NB: _add_node() gives us a node number, but we're going to
      * override it, because we know better. */
     node = o2cb_cluster_add_node(cluster, name);
-    if (!node)
-        return -ENOMEM;
+    if (!node){
+        rc = -ENOMEM;
+        goto out_error;
+    }

     rc = -EINVAL;
     num_s = j_config_get_attribute(cfs, "number");
@@ -178,7 +180,7 @@ static gint o2cb_config_fill_cluster(O2CBConfig *config, JConfig *cf,
 {
     gint rc;
     gulong val;
-    gchar *count, *ptr, *hb_mode = NULL;
+    gchar *count = NULL, *ptr = NULL, *hb_mode = NULL;
     O2CBCluster *cluster;
     JIterator *iter;
     JConfigStanza *n_cfs;
@@ -261,6 +263,7 @@ static gint o2cb_config_fill_cluster(O2CBConfig *config, JConfig *cf,
 out_error:
     g_free(hb_mode);
     g_free(match.value);
+    g_free(count);

     return rc;
 }  /* o2cb_config_fill_cluster() */
-- 1.8.4.3




More information about the Ocfs2-tools-devel mailing list