Bug #62242 [Com]: Memory Leak in xml_parser_create_ns()

From: Date: Wed, 06 Apr 2016 09:45:19 +0000
Subject: Bug #62242 [Com]: Memory Leak in xml_parser_create_ns()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200410@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62242&edit=1 ID: 62242 Comment by: jbr at emperion dot net Reported by: martinhv at arcor dot de Summary: Memory Leak in xml_parser_create_ns() Status: Open Type: Bug Package: XML related Operating System: Debian wheezy/sid PHP Version: 5.4Git-2012-06-06 (snap) Block user comment: N Private report: N New Comment: As per April 2016 the memory leak on Ubuntu 14:04 with PHP 5.5.9 still exists. Using JAXL xmpp package, this means that I have to restart the PHP daemon every few hours, which is a shame. SO I would be very happy if the memory leak could be fixed or if someone know how to avoid it. Previous Comments: ------------------------------------------------------------------------ [2012-06-06 10:14:00] martinhv at arcor dot de 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 this bug report at https://bugs.php.net/bug.php?id=62242&edit=1

« previous php.bugs (#200410) next »