|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-04-22 11:29 UTC] aldo at armiento dot com
Description:
------------
Assigning any value to a SimpleXML attribute produces a memory leak.
Reproduce code:
---------------
<?php
$xml = new SimpleXMLElement('<?xml version="1.0"?><root><test attribute="value"/></root>');
while(true) {
$xml->test['attribute'] = 'value';
}
echo $xml->asXML();
?>
Expected result:
----------------
<?xml version="1.0"?>
<root><test attribute="value"/></root>
Actual result:
--------------
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to
allocate 40 bytes) in /tmp/test_simplexml.php on line 5
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 05:00:01 2025 UTC |
This patch to php-5.2.5 sources in ext/simplexml/simplexml.c solve the problem. The problem is also present in php5.2-200804222030 snap --- simplexml.c.orig 2007-07-31 17:40:49.000000000 +0200 +++ simplexml.c 2008-04-23 00:16:00.276147006 +0200 @@ -702,11 +702,13 @@ convert_to_string(member); name = Z_STRVAL_P(member); node = sxe_get_element_by_name(sxe, node, &name, &type TSRMLS_CC); - if (!node) { - sxe_prop_dim_write(object, member, NULL, 1, 0, &node TSRMLS_CC); - type = SXE_ITER_NONE; - name = NULL; + if (node) { + return NULL; } + sxe_prop_dim_write(object, member, NULL, 1, 0, &node TSRMLS_CC); + type = SXE_ITER_NONE; + name = NULL; + MAKE_STD_ZVAL(return_value); _node_as_zval(sxe, node, return_value, type, name, sxe- >iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);