[Ocfs2-tools-devel] [PATCH] o2cb_ctl: Fix memory leak problems in jconfig.c
piaojun
piaojun at huawei.com
Fri Feb 27 22:29:49 PST 2015
Four memory leak problems were found in jconfig.c. The details of the
problems are described below:
1. In j_config_parse_any(), the 'scanner' should be destroyed after use.
2. In j_config_parse_stanza_attr(), the second parameter of g_string_free()
should be TRUE to free the character data.
3. In j_config_parse_file() and j_config_parse_memory(), the memory
allocated for 'cfc->cfs' and its members should be freed after use.
4.In j_config_free(), the memory allocated for 'cf->stanza_names' 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/jconfig.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/o2cb_ctl/jconfig.c b/o2cb_ctl/jconfig.c
index 5e68847..b2dde0a 100644
--- a/o2cb_ctl/jconfig.c
+++ b/o2cb_ctl/jconfig.c
@@ -289,6 +289,7 @@ static JConfig *j_config_parse_any(JConfigCtxt *cfc,
g_strerror(errno));
}
cfc->error = TRUE;
+ g_scanner_destroy(scanner);
return(NULL);
}
@@ -778,7 +779,7 @@ static void j_config_parse_stanza_attr(GScanner *scanner,
attribute_free:
g_free(attr_name);
- g_string_free(attr_value, FALSE);
+ g_string_free(attr_value, TRUE);
}
@@ -1240,6 +1241,8 @@ JConfig *j_config_parse_file(const gchar *filename)
if (cfc)
{
cf = j_config_parse_file_with_context(cfc, filename);
+ if (cfc->cfs)
+ j_config_free_stanza(cfc->cfs);
j_config_context_free(cfc);
}
@@ -1286,6 +1289,8 @@ JConfig *j_config_parse_memory(gchar *buffer, gint buf_len)
if (cfc)
{
cf = j_config_parse_memory_with_context(cfc, buffer, buf_len);
+ if (cfc->cfs)
+ j_config_free_stanza(cfc->cfs);
j_config_context_free(cfc);
}
@@ -1606,10 +1611,18 @@ static void j_config_free_config_node(gpointer key,
void j_config_free(JConfig *cf)
{
g_return_if_fail(cf != NULL);
-
+ GList *list;
g_hash_table_foreach(cf->stanzas, j_config_free_config_node, NULL);
g_hash_table_destroy(cf->stanzas);
g_free(cf->filename);
+ list = cf->stanza_names;
+ while (list)
+ {
+ g_free(list->data);
+ list->data = NULL;
+ list = list->next;
+ }
+ g_list_free(cf->stanza_names);
g_free(cf);
} /* j_config_free() */
--
1.8.4.3
More information about the Ocfs2-tools-devel
mailing list