diff options
author | Rob Bradford <rob@linux.intel.com> | 2008-11-18 16:05:24 +0000 |
---|---|---|
committer | Rob Bradford <rob@linux.intel.com> | 2008-11-18 16:05:24 +0000 |
commit | 8ba07cfd0ce6ba7cccb6fe7f853f8d356ccf0714 (patch) | |
tree | 0a54569516a49be43b69176ec03e6077c1b309e1 /rest/rest-xml-parser.c | |
parent | 3c06378429e66f2674145ed92f2896ed7dd55277 (diff) | |
download | librest-8ba07cfd0ce6ba7cccb6fe7f853f8d356ccf0714.tar.gz |
Free the siblings of a node when that node is freed.
Diffstat (limited to 'rest/rest-xml-parser.c')
-rw-r--r-- | rest/rest-xml-parser.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/rest/rest-xml-parser.c b/rest/rest-xml-parser.c index d1d41dd..46c0e8b 100644 --- a/rest/rest-xml-parser.c +++ b/rest/rest-xml-parser.c @@ -133,21 +133,41 @@ rest_xml_node_new () } void -rest_xml_node_free (RestXmlNode *node) +rest_xml_node_free (RestXmlNode *node_in) { GList *l; + RestXmlNode *next = NULL, *node; - l = g_hash_table_get_values (node->children); - while (l) + /* This node variable contains the current node we care about */ + node = node_in; + + while (node) { - rest_xml_node_free ((RestXmlNode *)l->data); - l = g_list_delete_link (l, l); - } + /* + * Save this pointer now since we are going to free the structure it + * contains soon. + */ + next = node->next; + + l = g_hash_table_get_values (node->children); + while (l) + { + rest_xml_node_free ((RestXmlNode *)l->data); + l = g_list_delete_link (l, l); + } - g_hash_table_unref (node->children); - g_hash_table_unref (node->attrs); - g_free (node->content); - g_slice_free (RestXmlNode, node); + g_hash_table_unref (node->children); + g_hash_table_unref (node->attrs); + g_free (node->content); + g_slice_free (RestXmlNode, node); + + /* + * Free the next in the chain by updating node. If we're at the end or + * there are no siblings then the next = NULL definition deals with this + * case + */ + node = next; + } } const gchar * |