ID: 44798 User updated by: aldo at armiento dot com Reported By: aldo at armiento dot com Status: Open Bug Type: SimpleXML related Operating System: Linux 2.6.18-686 PHP Version: 5.2.5 New Comment:
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); Previous Comments: ------------------------------------------------------------------------ [2008-04-22 11:29:07] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44798&edit=1