[Ocfs2-tools-devel] [PATCH 1/3] o2cb_ctl: fix memory leak in jconfig.c
Joseph Qi
joseph.qi at huawei.com
Thu Mar 10 00:55:49 PST 2016
From: Jun Piao <piaojun at huawei.com>
There are 4 memory leak problems in jconfig.c.
In j_config_parse_any(), the 'scanner' should be destroyed after use.
In j_config_parse_stanza_attr(), the second parameter of
g_string_free() should be TRUE to free the character data.
In j_config_parse_file() and j_config_parse_memory(), the memory
allocated for 'cfc->cfs' and its members should be freed after use.
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>
Signed-off-by: Joseph Qi <joseph.qi at huawei.com>
---
o2cb_ctl/jconfig.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/o2cb_ctl/jconfig.c b/o2cb_ctl/jconfig.c
index 5e68847..0cb90d1 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,21 @@ 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