Bug #72793 [Ver]: xml_parser_free leaks mem when execute xml_set_object
Edit report at https://bugs.php.net/bug.php?id=72793&edit=1
ID: 72793
Updated by: cmb@php.net
Reported by: daisukeunoz1zi at gmail dot com
Summary: xml_parser_free leaks mem when execute
xml_set_object
Status: Verified
Type: Bug
Package: *XML functions
Operating System: CentOS
PHP Version: 7.0.9
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This issue affects PHP 7 only, and there it can't be fixed without
causing a considerable BC break.[1] Instead the user of
xml_set_object() has to make sure to break the reference cycle
between the parser and the custom object (typically by unsetting
the parser when they're done). This has to be documented.
[1] <http://marc.info/?t=147082649400006&r=1&w=2>
Previous Comments:
------------------------------------------------------------------------
[2016-08-09 07:17:27] daisukeunoz1zi at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.xml-parser-free
---
The memory usage of the script below goes through the roof.
It happen only when execute "xml_set_object".
It does not happen when I execute "unset($this->parser);".
Test script:
---------------
<?php
class xml {
var $parser;
function __construct()
{
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
}
function parse($data)
{
xml_parse($this->parser, $data);
}
function free(){
xml_parser_free($this->parser);
//unset($this->parser);
}
}
$xml_test = '<?xml version="1.0"
encoding="utf-8"?><test></test>';
for ($i = 0; $i < 100000000; $i++) {
$xml_parser = new xml();
$xml_parser->parse($xml_test);
$xml_parser->free();
unset($xml_parser);
}
?>
Expected result:
----------------
Empty output.
Actual result:
--------------
Out of memory error.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72793&edit=1
Thread (3 messages)