php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #72793 xml_parser_free leaks mem when execute xml_set_object
Submitted: 2016-08-09 07:17 UTC Modified: 2016-08-12 09:50 UTC
From: daisukeunoz1zi at gmail dot com Assigned: cmb (profile)
Status: Closed Package: *XML functions
PHP Version: 7.0.9 OS: CentOS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: daisukeunoz1zi at gmail dot com
New email:
PHP Version: OS:

 

 [2016-08-09 07:17 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-09 17:28 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2016-08-12 09:50 UTC] cmb@php.net
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>
 [2016-08-12 09:50 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2016-08-12 10:46 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=339867
Log: Fix #72793: xml_parser_free leaks mem when execute xml_set_object
 [2016-08-12 10:57 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=92a076a92bf7d2fb20e0bc5d376ce65fab268b52
Log: Fix #72793: xml_parser_free leaks mem when execute xml_set_object
 [2016-08-12 10:57 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2016-10-17 10:09 UTC] bwoebi@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=92a076a92bf7d2fb20e0bc5d376ce65fab268b52
Log: Fix #72793: xml_parser_free leaks mem when execute xml_set_object
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=1ff86a66e656b053e99c82aa44989cb5c953c4e4
Log: Fix #72793: xml_parser_free leaks mem when execute xml_set_object
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 16:01:29 2024 UTC