[gegl] Destroy resources if gegl_node_new_from_xml() fails
- From: Martin Nordholts <martinn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] Destroy resources if gegl_node_new_from_xml() fails
- Date: Wed, 23 Jun 2010 18:55:28 +0000 (UTC)
commit a621b67f2fd77daffdd9f8ae162e6c9deabff7f3
Author: Danny Robson <danny blubinc net>
Date: Sat May 22 20:11:25 2010 +1000
Destroy resources if gegl_node_new_from_xml() fails
If XML graph construction failed, some nodes and auxilliary data
structures would not be freed. Allows returning of NULL on parsing
failure.
gegl/gegl-xml.c | 29 +++++++++++++++++++++++------
1 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/gegl/gegl-xml.c b/gegl/gegl-xml.c
index e44991c..32ee312 100644
--- a/gegl/gegl-xml.c
+++ b/gegl/gegl-xml.c
@@ -55,6 +55,7 @@ enum
STATE_TREE_FIRST_CHILD
};
+
struct _ParseData
{
gint state;
@@ -515,6 +516,7 @@ GeglNode *gegl_node_new_from_xml (const gchar *xmldata,
glong time = gegl_ticks ();
ParseData pd = { 0, };
GMarkupParseContext *context;
+ gboolean success = FALSE;
g_return_val_if_fail (xmldata != NULL, NULL);
@@ -522,19 +524,34 @@ GeglNode *gegl_node_new_from_xml (const gchar *xmldata,
pd.refs = NULL;
pd.path_root = path_root;
- context = g_markup_parse_context_new (&parser, 0, &pd, NULL);
- g_markup_parse_context_parse (context, xmldata, strlen (xmldata), NULL);
-
- /* connect clones */
- g_list_foreach (pd.refs, each_ref, &pd);
+ g_list_free (pd.refs);
+ context = g_markup_parse_context_new (&parser, 0, &pd, NULL);
+ success = g_markup_parse_context_parse (context,
+ xmldata,
+ strlen (xmldata),
+ NULL);
+ if (success)
+ {
+ /* connect clones */
+ g_list_foreach (pd.refs, each_ref, &pd);
+ }
+ else
+ {
+ if (pd.gegl)
+ {
+ g_object_unref (pd.gegl);
+ pd.gegl = NULL;
+ }
+ }
+ g_list_free (pd.refs);
g_markup_parse_context_free (context);
g_hash_table_destroy (pd.ids);
time = gegl_ticks () - time;
gegl_instrument ("gegl", "gegl_parse_xml", time);
- return GEGL_NODE (pd.gegl);
+ return success ? GEGL_NODE (pd.gegl) : NULL;
}
GeglNode *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]