summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-04-08 10:35:54 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-04-08 10:35:54 +0200
commit7e91fcd7f95e304aef4c76d1af20da3f40f10594 (patch)
tree6e1c6c004e55a29fd0a91f444bc367d6dba3a602
parenta0df5f3b542abfd1078ac04e9a2081a1f71e3b11 (diff)
downloadphp-git-7e91fcd7f95e304aef4c76d1af20da3f40f10594.tar.gz
Fix memory leak introduced by fixing bug #78221
We have to free the retrieved text content; to keep the code readable, we extract a helper function to check for empty nodes. Unfortunately, we cannot use xmlIsBlankNode(), because that also recognizes whitespace only text content. We also make sure to properly handle NULL returns from xmlNodeGetContent().
-rw-r--r--ext/dom/php_dom.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c
index ed67f047fa..def54c99fb 100644
--- a/ext/dom/php_dom.c
+++ b/ext/dom/php_dom.c
@@ -1358,6 +1358,14 @@ xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *l
/* }}} */
/* }}} end dom_element_get_elements_by_tag_name_ns_raw */
+static inline zend_bool is_empty_node(xmlNodePtr nodep)
+{
+ xmlChar *strContent = xmlNodeGetContent(nodep);
+ zend_bool ret = strContent == NULL || *strContent == '\0';
+ xmlFree(strContent);
+ return ret;
+}
+
/* {{{ void dom_normalize (xmlNodePtr nodep) */
void dom_normalize (xmlNodePtr nodep)
{
@@ -1383,8 +1391,7 @@ void dom_normalize (xmlNodePtr nodep)
break;
}
}
- strContent = xmlNodeGetContent(child);
- if (*strContent == '\0') {
+ if (is_empty_node(child)) {
nextp = child->next;
xmlUnlinkNode(child);
php_libxml_node_free_resource(child);