From: [EMAIL PROTECTED]
Operating system: Any
PHP version: 5.2.5
PHP Bug Type: Scripting Engine problem
Bug description: Memory leak on some functions with implicit object
__toString() call
Description:
------------
Under certain circumenstances, the implicit call to __toString() on an
object may lead to memory leaks.
In the reproducable example, the following line leaks ($o is a simply
object):
md5($o);
But this line doesn't:
md5($o->__toString());
This only applies to certain functions, I've identifier md5, sha1 and
crc32.
If I try other examples like strstr or strlen, there's no leak at all.
A wild guess is that this maybe has to do whether the function internally
uses zend_parse_parameters() or zend_get_parameters_ex().
The function which leak use zend_parse_parameters(), the others don't.
But this may completely accidental.
It seems very related to bug#38591. However I don't see how bug#38604 is
related to this issue (mentioned in bug#38591).
This leak was most notable found in an application which is supposed to
run for a long time, even hours. So usually within web application this is
not an issue.
Reproduce code:
---------------
<?php
class Foo {
function __toString() {
return 'foo';
}
}
for ($i = 0; $i < 1e5; $i++) {
$o = new Foo;
# leaks
md5($o);
# does not leak
#md5($o->__toString());
# does not leak either way
# strstr($o, 'f');
#strstr($o->__toString(), 'f');
if ($i % 1e3 == 0) {
printf("%u: %1.2f KB\n",
$i, memory_get_usage(true) / 1024);
}
}
Expected result:
----------------
Constant memory usage.
Actual result:
--------------
Memory grows and grows.
--
Edit bug report at http://bugs.php.net/?id=43450&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=43450&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=43450&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=43450&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=43450&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43450&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=43450&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43450&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43450&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43450&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43450&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43450&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=43450&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=43450&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43450&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43450&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43450&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43450&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43450&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43450&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43450&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43450&r=mysqlcfg