Skip to content

Commit dd73b38

Browse files
committed
Fix GH-17145: DOM memory leak
Because the use of RETURN instead of RETVAL, the freeing code could not be executed. This only is triggerable if the content of the attribute is mixed text and entities, so it wasn't noticed earlier.
1 parent b86308c commit dd73b38

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/dom/php_dom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ void php_dom_get_content_into_zval(const xmlNode *nodep, zval *return_value, boo
23752375
case XML_ATTRIBUTE_NODE: {
23762376
bool free;
23772377
xmlChar *value = php_libxml_attr_value((const xmlAttr *) nodep, &free);
2378-
RETURN_STRING_FAST((const char *) value);
2378+
RETVAL_STRING_FAST((const char *) value);
23792379
if (free) {
23802380
xmlFree(value);
23812381
}

ext/dom/tests/gh17145.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-17145 (DOM memory leak)
3+
--EXTENSIONS--
4+
dom
5+
--CREDITS--
6+
YuanchengJiang
7+
--FILE--
8+
<?php
9+
$element = new DOMElement("N", "W", "y");
10+
$attr = new DOMAttr("c" , "n");
11+
$doc = new DOMDocument();
12+
$doc->appendChild($element);
13+
$element->setAttributeNodeNS($attr);
14+
$attr->appendChild($doc->createEntityReference('amp'));
15+
echo $attr->value;
16+
?>
17+
--EXPECT--
18+
n&

0 commit comments

Comments
 (0)