Skip to content

Commit 29fcf12

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 29fcf12

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-17145 (DOM memory leak)
3+
--EXTENSIONS--
4+
dom
5+
--CREDITS--
6+
YuanchengJiang
7+
--SKIPIF--
8+
<?php
9+
if (LIBXML_VERSION < 21300) die("skip Upstream libxml bug causes incorrect output, fixed in GNOME/libxml2@b8597f4");
10+
?>
11+
--FILE--
12+
<?php
13+
$element = new DOMElement("N", "W", "y");
14+
$attr = new DOMAttr("c" , "n");
15+
$doc = new DOMDocument();
16+
$doc->appendChild($element);
17+
$element->setAttributeNodeNS($attr);
18+
$attr->appendChild($doc->createEntityReference('amp'));
19+
echo $attr->value;
20+
?>
21+
--EXPECT--
22+
n&

0 commit comments

Comments
 (0)