#29838 [Bgs]: Memory leak in sprintf argument swapping
| From: | tim at digicol dot de | Date: | Thu, 26 Aug 2004 07:31:25 +0000 |
| Subject: | #29838 [Bgs]: Memory leak in sprintf argument swapping | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-65264@lists.php.net to get a copy of this message | ||
ID: 29838
User updated by: tim at digicol dot de
Reported By: tim at digicol dot de
Status: Bogus
Bug Type: Strings related
Operating System: SuSE Linux 8.2 (i586)
PHP Version: 4.3.8
New Comment:
This is *not* bogus.
Small code change - assign the sprintf() result to $x:
for ($i = 1; $i <= 100000; $i++)
$x = sprintf($format, $num, $location);
Same result, still leaks memory. I don't see 100000 temporary variables
here, just $i, $x, $format, $num, $location.
Previous Comments:
------------------------------------------------------------------------
[2004-08-26 02:04:53] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You created 100000 temporary variables inside PHP, what do
you expect...
------------------------------------------------------------------------
[2004-08-25 17:27:44] tim at digicol dot de
Also happens on PHP 4.3.9RC1 ...
------------------------------------------------------------------------
[2004-08-25 17:15:04] tim at digicol dot de
Description:
------------
Using argument swapping in sprintf() or printf() calls makes PHP leak
memory. (I've been running this code using the PHP CLI binary.)
Have been able to reproduce this with PHP 4.3.7 as well.
./configure --with-config-file-path=/usr/local/php/conf --enable-cli
--enable-track-vars --disable-magic-quotes --enable-xml
--enable-sysvsem --enable-sysvshm
--with-apxs=/usr/local/apache/bin/apxs --disable-debug --enable-ftp
--enable-wddx --enable-sigchild --enable-inline-optimization
--enable-exif --with-pgsql=/usr/local/pgsql --prefix=/usr/local/php
--with-oci8=/dot/oracle/product/9.2.0 --with-db3=/usr/local/db3
--with-zlib --with-dom --with-gd --with-mhash=/usr/local/mhash
--enable-mbstring=all --enable-mbstr-enc-trans --enable-mbregex
--disable-pic --with-gdbm --enable-pcntl --enable-sysvmsg
--with-iconv=/dot/local/iconv --enable-memory-limit
Reproduce code:
---------------
<?php
$b = memory_get_usage();
$location = "zoo";
$num = 2;
// No memory leak:
// $format = "The %s contains %s monkeys\n";
// Memory leak:
$format = "The %2\$s contains %1\$d monkeys\n";
for ($i = 1; $i <= 100000; $i++)
sprintf($format, $num, $location);
echo "Grown by " . (memory_get_usage() - $b) . "\n";
?>
Expected result:
----------------
Grown by 376
Actual result:
--------------
Grown by 4000336
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29838&edit=1