From 4e06242c80836b8c4f2ed442d58dc7f249a36183 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 3 Aug 2018 13:15:00 +0100 Subject: HTMLCollection.namedItem: Squash leak of id_name. --- src/html/html_collection.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src') 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 */ -- cgit v1.2.3