php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41452 possible memory leak in DomNode->first_child
Submitted: 2007-05-21 06:45 UTC Modified: 2007-06-12 14:14 UTC
From: mike at netagi dot com Assigned:
Status: Wont fix Package: DOM XML related
PHP Version: 4.4.7 OS: Ubuntu Linux 6.06 LTS
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mike at netagi dot com
New email:
PHP Version: OS:

 

 [2007-05-21 06:45 UTC] mike at netagi dot com
Description:
------------
Directly after calling node->first_child the memory usage increases and does not drop. This might also be the case with has_child_nodes.

I've tried numerous test cases (as I am trying to keep memory consumption low) but have had no luck. I've tried using functions so the variables lose scope etc. Whatever gets created during the first_child can never be freed.

I understand that the Zend Engine may be caching some structures, however i have allocated 120 Meg to PHP4 CLI and it's still returning an out of memory error. If I disable first_child the script runs without any issues.



Reproduce code:
---------------
$doc = domxml_open_file("import_prod_cat.xml");
$xpath = $doc->xpath_new_context();
$obj = $xpath->xpath_eval('//import_catprod_link');
$nodeset = $obj->nodeset;
foreach($nodeset as $node ) {
        print "S1 " . memory_get_usage() . "\n";
        if( $node->has_child_nodes() ) {
                print " S2 " . memory_get_usage() . "\n";
                $child = $node->first_child();
                print " S3 " . memory_get_usage() . "\n";
                unset($child);
                unset($node);
                print " S4 " . memory_get_usage() . "\n";
        }
        print " S6 " . memory_get_usage() . "\n";
}
$doc->free();

Actual result:
--------------
S1 21202968
 S2 21203040
 S3 21204416
 S4 21204456
 S5 21204456

S1 21204456
 S2 21204456
 S3 21205184
 S4 21205224
 S5 21205224

S1 21205224
 S2 21205224
 S3 21205952
 S4 21205992
 S5 21205992

S1 21205992
 S2 21205992
 S3 21206720
 S4 21206760
 S5 21206760

... etc until it runs out of ram.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-12 14:14 UTC] rrichards@php.net
You need to upgrade to PHP 5 and ext/DOM.
This is just one of the reasons for the re-write of ext/domxml. Unset() and variable scope have no effect on the structures created by ext/domxml and they are not freed until the request is completed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 08 05:01:28 2024 UTC