PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Web Services » XML_RPC » Bug #4780

Memory leak in XML_RPC_Message::parseResponse

Details

Submitted2005-07-10 06:33 UTC
Frombrion at pobox dot com
Assigneddanielc
StatusClosed
PackageXML_RPC
PHP Version4.3.11
OSLinux
Roadmaps(Not assigned)

Comments

[2005-07-10 06:33 UTC] brion at pobox dot com

Description:
------------
XML parsing that happens under XML_RPC_Message::parseResponse
stuffs data into a global array, $XML_RPC_xh. This array's
contents are never cleared, and each individual request
performed adds a new set of data as a sub-array to it.

As a result, even a minimal request leaks about 1kb. When you
make 1.5 million requests in a long-running process, this adds
up to some serious swap usage.

Tested with PHP 4.3.10 (Ubuntu package) and 4.3.11 (manually
compiled on Red Hat/Fedora), PEAR::XML_RPC 1.3.2 freshly
upgraded.

Reproduce code:
---------------
<?php
require_once 'XML/RPC.php';
$initial = memory_get_usage();
for( $i = 1; true; $i++ ) {
$client = new XML_RPC_Client( '/SearchUpdater', 'localhost', 8124 );
$message = new XML_RPC_Message( 'searchupdater.getStatus', array() );
$client->send( $message );
$mem = memory_get_usage();
$delta = ($mem - $initial) / $i;
if( $i % 100 == 0 ) echo "$i $mem $delta\n";
}
?>

Quick fix is to clear $XML_RPC_xh when we begin. Sample patch: http://leuksman.com/pages/xmlrpc/leak

Expected result:
----------------
Memory usage should remain fairly steady, with no or small
per-iteration growth:
100 260376 317.36
200 267864 196.12
300 271536 142.986666667
...
13100 271536 3.27450381679
...

Actual result:
--------------
Memory usage grows by about a kilobyte per iteration:
100 348920 1204.72
200 456280 1139.16
300 560504 1106.85333333
...
PHP Fatal error: Allowed memory size of 8388608 bytes
exhausted (tried to allocate 32769 bytes) in /usr/share/php/
XML/RPC.php on line 663

[2006-02-24 22:34 UTC] trent dot larson at gmail dot com

PHP has a default memory limit of 8M(see php.ini, find memory_limit). Try changing that to a higher number and attemp running that script again. It worked for me.

(I found this solution from this posting: http://www.mailarchives.org/list/debian-user/msg/2004/30319, thanks Jacob)