summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2018-08-03 13:15:00 +0100
committerMichael Drake <michael.drake@codethink.co.uk>2018-08-03 13:15:00 +0100
commit4e06242c80836b8c4f2ed442d58dc7f249a36183 (patch)
tree6d5f15307e2d46fbd8bb7802b4deb0cbc150751b
parent4d1731bba2d6091e25c7d1d57b0e547c8ac30db9 (diff)
downloadlibdom-4e06242c80836b8c4f2ed442d58dc7f249a36183.tar.gz
libdom-4e06242c80836b8c4f2ed442d58dc7f249a36183.tar.bz2
HTMLCollection.namedItem: Squash leak of id_name.
-rw-r--r--src/html/html_collection.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/html/html_collection.c b/src/html/html_collection.c
index cba2b2d..7bb55b6 100644
--- a/src/html/html_collection.c
+++ b/src/html/html_collection.c
@@ -215,7 +215,8 @@ dom_exception dom_html_collection_named_item(dom_html_collection *col,
struct dom_node_internal *n = col->root;
dom_html_document *doc = (dom_html_document *)dom_node_get_owner(n);
dom_exception err;
- while (n != NULL) {
+
+ while (n != NULL) {
if (n->type == DOM_ELEMENT_NODE &&
col->ic(n, col->ctx) == true) {
dom_string *id = NULL;
@@ -227,16 +228,15 @@ dom_exception dom_html_collection_named_item(dom_html_collection *col,
return err;
}
- if (id != NULL && dom_string_isequal(name, id)) {
- *node = (struct dom_node *) n;
- dom_node_ref(n);
- dom_string_unref(id);
-
- return DOM_NO_ERR;
- }
+ if (id != NULL) {
+ if (dom_string_isequal(name, id)) {
+ *node = dom_node_ref(n);
+ dom_string_unref(id);
- if (id != NULL)
+ return DOM_NO_ERR;
+ }
dom_string_unref(id);
+ }
/* Check for Name attr if id not matched/found */
err = _dom_element_get_attribute((dom_element *)n,
@@ -244,14 +244,16 @@ dom_exception dom_html_collection_named_item(dom_html_collection *col,
if(err != DOM_NO_ERR) {
return err;
}
- if (id_name != NULL && dom_string_isequal(name, id_name)) {
- *node = (struct dom_node *) n;
- dom_node_ref(n);
- dom_string_unref(id_name);
- return DOM_NO_ERR;
- }
+ if (id_name != NULL) {
+ if (dom_string_isequal(name, id_name)) {
+ *node = dom_node_ref(n);
+ dom_string_unref(id_name);
+ return DOM_NO_ERR;
+ }
+ dom_string_unref(id_name);
+ }
}
/* Depth first iterating */