Bug #62242 [NEW]: Memory Leak in xml_parser_create_ns()
| From: | martinhv at arcor dot de | Date: | Wed, 06 Jun 2012 10:14:01 +0000 |
| Subject: | Bug #62242 [NEW]: Memory Leak in xml_parser_create_ns() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-171076@lists.php.net to get a copy of this message | ||
From: martinhv at arcor dot de
Operating system: Debian wheezy/sid
PHP version: 5.4Git-2012-06-06 (snap)
Package: XML related
Bug Type: Bug
Bug description:Memory Leak in xml_parser_create_ns()
Description:
------------
The function xml_parser_create_ns() use memory that doesn't freed after
xml_parser_free() is called. This memory isn't registered by php and the
function memory_get_usage() doesn't report it. But you can see the eating
memory via the ps command. (See the actual result below)
If the function xml_parser_create() is used, the used memory stagnates to a
constant value. So no memory leak exists. (See the expected result below)
If no xml_set_element_handler() is called, there isn't a memory leak, too.
So only the combination of xml_parser_create_ns() with
xml_set_element_handler() produced a memory leak!
I tested with the PHP snapshot 5.4 from 2012-06-05 on Debian Wheezy Alpha1
with libxml2 version 2.7.8.dfsg-9.1. But many other PHP versions reproduce
the bug, too.
Test script:
---------------
#!/usr/local/bin/php
<?php
$xml='<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<root xmlns="http://test/ns">
<test name="Name" value="Value" key="Key" id="Id"
test="Test"/>
<test name="Name" value="Value" key="Key" id="Id"
test="Test"/>
<test name="Name" value="Value" key="Key" id="Id"
test="Test"/>
</root>';
for ($i=0; $i<10000; $i++) {
$xml_parser = xml_parser_create_ns('utf-8', '@');
xml_set_element_handler($xml_parser, 'start_tag_handler',
'end_tag_handler');
xml_parse($xml_parser, $xml, true);
xml_parser_free($xml_parser);
$xml_parser = NULL;
if (($i % 1000) == 0)
echo "memory_get_usage(): ".memory_get_usage(true)." bytes\n".
"real memory size: ".(exec("ps h -C test2.php -o rsz")*1024)."
bytes\n";
}
function start_tag_handler($parser, $name, $attribs) {
}
function end_tag_handler($parser, $name) {
}
?>
Expected result:
----------------
memory_get_usage(): 262144 bytes
real memory size: 3743744 bytes
memory_get_usage(): 262144 bytes
real memory size: 3743744 bytes
memory_get_usage(): 262144 bytes
real memory size: 3796992 bytes
memory_get_usage(): 262144 bytes
real memory size: 3796992 bytes
memory_get_usage(): 262144 bytes
real memory size: 3796992 bytes
memory_get_usage(): 262144 bytes
real memory size: 3796992 bytes
memory_get_usage(): 262144 bytes
real memory size: 3796992 bytes
memory_get_usage(): 262144 bytes
real memory size: 3796992 bytes
memory_get_usage(): 262144 bytes
real memory size: 3796992 bytes
memory_get_usage(): 262144 bytes
real memory size: 3796992 bytes
Actual result:
--------------
memory_get_usage(): 262144 bytes
real memory size: 3772416 bytes
memory_get_usage(): 262144 bytes
real memory size: 4222976 bytes
memory_get_usage(): 262144 bytes
real memory size: 4657152 bytes
memory_get_usage(): 262144 bytes
real memory size: 5091328 bytes
memory_get_usage(): 262144 bytes
real memory size: 5750784 bytes
memory_get_usage(): 262144 bytes
real memory size: 6225920 bytes
memory_get_usage(): 262144 bytes
real memory size: 6656000 bytes
memory_get_usage(): 262144 bytes
real memory size: 7090176 bytes
memory_get_usage(): 262144 bytes
real memory size: 7524352 bytes
memory_get_usage(): 262144 bytes
real memory size: 7958528 bytes
--
Edit bug report at https://bugs.php.net/bug.php?id=62242&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62242&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62242&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62242&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=62242&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62242&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=62242&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=62242&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=62242&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=62242&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=62242&r=support
Expected behavior: https://bugs.php.net/fix.php?id=62242&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=62242&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=62242&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=62242&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62242&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62242&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=62242&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=62242&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=62242&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=62242&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=62242&r=mysqlcfg