From: arnout at argeweb dot nl
Operating system: FreeBSD 5.4-RELEASE-p11
PHP version: 5.1.2
PHP Bug Type: Scripting Engine problem
Bug description: string concat
Description:
------------
Using the following code leaks 32 bytes of memory.
$doe = 'yoyoyo';
echo "john $doe";
PHP 5.1.2 (cli) (built: Feb 22 2006 16:17:32)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
with Zend Extension Manager v1.0.10, Copyright (c) 2003-2006, by Zend
Technologies
with Zend Optimizer v3.0.0-Beta2, Copyright (c) 1998-2006, by Zend
Technologies
Reproduce code:
---------------
<?php
@ob_end_flush(); // to be sure
function fake1( $string ){
echo "kaas ".$string;
}
function fake2( $string ){
echo "kaas $string";
}
function fake3( $string ){
$string = "kaas $string";
}
function fake4( $string ){
echo "kaas $string asdf";
}
echo "<P><b>function fake1</b></p>";
for( $i = 0;$i < 10; $i++ ){
echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
fake1( "string" );
echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
}
echo "<P><b>function fake2</b></p>";
for( $i = 0;$i < 10; $i++ ){
echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
fake2( "string" );
echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
}
echo "<P><b>function fake3</b></p>";
for( $i = 0;$i < 10; $i++ ){
echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
fake3( "string" );
echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
}
echo "<P><b>function fake4</b></p>";
for( $i = 0;$i < 10; $i++ ){
echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
fake4( "string" );
echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
}
?>
Expected result:
----------------
Hardly any change in memory usage.
Actual result:
--------------
function fake1
Memory at 0: 42920
kaas stringMemory at 0: 42984
Memory at 1: 42984
kaas stringMemory at 1: 42984
Memory at 2: 42984
kaas stringMemory at 2: 42984
Memory at 3: 42984
kaas stringMemory at 3: 42984
...etcetera... +64 bytes, only once.
function fake2
Memory at 0: 42984
kaas stringMemory at 0: 43000
Memory at 1: 43000
kaas stringMemory at 1: 43016
Memory at 2: 43016
kaas stringMemory at 2: 43032
Memory at 3: 43032
kaas stringMemory at 3: 43048
...etcetera... +16 bytes
function fake3
Memory at 0: 43144
Memory at 0: 43160
Memory at 1: 43160
Memory at 1: 43176
Memory at 2: 43176
Memory at 2: 43192
Memory at 3: 43192
Memory at 3: 43208
...etcetera... +16 bytes
function fake4
Memory at 0: 43304
kaas string asdfMemory at 0: 43328
Memory at 1: 43328
kaas string asdfMemory at 1: 43352
Memory at 2: 43352
kaas string asdfMemory at 2: 43376
...etcetera... +24 bytes
--
Edit bug report at http://bugs.php.net/?id=36924&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36924&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36924&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36924&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36924&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36924&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36924&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36924&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36924&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36924&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36924&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36924&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36924&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36924&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36924&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36924&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36924&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36924&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36924&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36924&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36924&r=mysqlcfg