Skip to content

Commit 7e91fcd

Browse files
committed
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().
1 parent a0df5f3 commit 7e91fcd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ext/dom/php_dom.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,14 @@ xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *l
13581358
/* }}} */
13591359
/* }}} end dom_element_get_elements_by_tag_name_ns_raw */
13601360

1361+
static inline zend_bool is_empty_node(xmlNodePtr nodep)
1362+
{
1363+
xmlChar *strContent = xmlNodeGetContent(nodep);
1364+
zend_bool ret = strContent == NULL || *strContent == '\0';
1365+
xmlFree(strContent);
1366+
return ret;
1367+
}
1368+
13611369
/* {{{ void dom_normalize (xmlNodePtr nodep) */
13621370
void dom_normalize (xmlNodePtr nodep)
13631371
{
@@ -1383,8 +1391,7 @@ void dom_normalize (xmlNodePtr nodep)
13831391
break;
13841392
}
13851393
}
1386-
strContent = xmlNodeGetContent(child);
1387-
if (*strContent == '\0') {
1394+
if (is_empty_node(child)) {
13881395
nextp = child->next;
13891396
xmlUnlinkNode(child);
13901397
php_libxml_node_free_resource(child);

0 commit comments

Comments
 (0)