summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-05-23 14:44:41 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2013-05-23 14:44:41 (GMT)
commitf687048c44408d07f0e6c4f3dcb9d7cd8d67e767 (patch)
treed0d1e76cc168f536898a5ec87841a813c58f9a0b
parent490a8c63bc0b5c0204c48b368ad81ac4d2a9a8bf (diff)
downloadlibdom-f687048c44408d07f0e6c4f3dcb9d7cd8d67e767.tar.gz
libdom-f687048c44408d07f0e6c4f3dcb9d7cd8d67e767.tar.bz2
Fix _dom_node_is_equal leaking all its refs. Replace C++ comments. Flag broken bit with TODO.
-rw-r--r--src/core/node.c97
1 files changed, 65 insertions, 32 deletions
diff --git a/src/core/node.c b/src/core/node.c
index 1b06642..a920797 100644
--- a/src/core/node.c
+++ b/src/core/node.c
@@ -1593,75 +1593,108 @@ dom_exception _dom_node_lookup_namespace(dom_node_internal *node,
dom_exception _dom_node_is_equal(dom_node_internal *node,
dom_node_internal *other, bool *result)
{
- dom_exception err;
- dom_string *s1, *s2;
- dom_namednodemap *m1, *m2;
- dom_nodelist *l1, *l2;
+ dom_exception err = DOM_NO_ERR;
+ dom_string *s1 = NULL, *s2 = NULL;
+ dom_namednodemap *m1 = NULL, *m2 = NULL;
+ dom_nodelist *l1 = NULL, *l2 = NULL;
+ *result = false;
+ /* Compare the node types */
if (node->type != other->type){
- *result = false;
- return DOM_NO_ERR;
+ /* different */
+ err = DOM_NO_ERR;
+ goto cleanup;
}
assert(node->owner != NULL);
assert(other->owner != NULL);
+ /* Compare the node names */
err = dom_node_get_node_name(node, &s1);
- if (err != DOM_NO_ERR)
- return err;
+ if (err != DOM_NO_ERR) {
+ /* error */
+ goto cleanup;
+ }
err = dom_node_get_node_name(other, &s2);
- if (err != DOM_NO_ERR)
- return err;
+ if (err != DOM_NO_ERR) {
+ /* error */
+ goto cleanup;
+ }
if (dom_string_isequal(s1, s2) == false) {
- *result = false;
- return DOM_NO_ERR;
+ /* different */
+ goto cleanup;
}
-
+
+ /* TODO: surely this bit is broken */
if (node->name != other->name ||
node->namespace != other->namespace ||
node->prefix != other->prefix) {
- *result = false;
- return DOM_NO_ERR;
+ /* different */
+ goto cleanup;
}
if (dom_string_isequal(node->value, other->value) == false) {
- *result = false;
- return DOM_NO_ERR;
+ /* different */
+ goto cleanup;
}
- // Following comes the attributes
+ /* Compare the attributes */
err = dom_node_get_attributes(node, &m1);
- if (err != DOM_NO_ERR)
- return err;
+ if (err != DOM_NO_ERR) {
+ /* error */
+ goto cleanup;
+ }
err = dom_node_get_attributes(other, &m2);
- if (err != DOM_NO_ERR)
- return err;
+ if (err != DOM_NO_ERR) {
+ /* error */
+ goto cleanup;
+ }
if (dom_namednodemap_equal(m1, m2) != true) {
- *result = false;
- return DOM_NO_ERR;
+ /* different */
+ goto cleanup;
}
- // Finally the childNodes
+ /* Compare the children */
err = dom_node_get_child_nodes(node, &l1);
- if (err != DOM_NO_ERR)
- return err;
+ if (err != DOM_NO_ERR) {
+ /* error */
+ goto cleanup;
+ }
err = dom_node_get_child_nodes(other, &l2);
- if (err != DOM_NO_ERR)
- return err;
+ if (err != DOM_NO_ERR) {
+ /* error */
+ goto cleanup;
+ }
if (dom_nodelist_equal(l1, l2) != true) {
- *result = false;
- return DOM_NO_ERR;
+ /* different */
+ goto cleanup;
}
*result = true;
- return DOM_NO_ERR;
+cleanup:
+ if (s1 != NULL)
+ dom_string_unref(s1);
+ if (s2 != NULL)
+ dom_string_unref(s2);
+
+ if (m1 != NULL)
+ dom_namednodemap_unref(m1);
+ if (m2 != NULL)
+ dom_namednodemap_unref(m2);
+
+ if (l1 != NULL)
+ dom_nodelist_unref(l1);
+ if (l2 != NULL)
+ dom_nodelist_unref(l2);
+
+ return err;
}
/**