[Ocfs2-tools-devel] [PATCH 2/3] o2cb_ctl: fix memory leak in o2cb_config.c
Gang He
ghe at suse.com
Thu Mar 10 01:10:46 PST 2016
>>>
> From: Jun Piao <piaojun at huawei.com>
>
> There are 2 memory leak problems in o2cb_config.c.
>
> In o2cb_cluster_fill_node(), the memory allocated for 'name' should
> be freed before the function return.
>
> In o2cb_config_fill_cluster(), the 'count' should be freed after use.
>
> Signed-off-by: Jun Piao <piaojun at huawei.com>
> Signed-off-by: Joseph Qi <joseph.qi at huawei.com>
reviewed-by: Gang He <ghe at suse.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..17749f8 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, *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