Skip to content

Commit 4656c22

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. Closes GH-17147.
1 parent ccc6c0f commit 4656c22

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ PHP NEWS
1717
- DBA:
1818
. Skip test if inifile is disabled. (orlitzky)
1919

20+
- DOM:
21+
. Fixed bug GH-17145 (DOM memory leak). (nielsdos)
22+
2023
- FFI:
2124
. Fixed bug #79075 (FFI header parser chokes on comments). (nielsdos)
2225

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)