From:
Operating system: OSX 10.7.3
PHP version: 5.4.0
Package: PCRE related
Bug Type: Bug
Bug description:preg_replace_callback memory leak
Description:
------------
$ ./ptest.php
Test preg_replace_callback
Iteration number 0
Iteration number 1
....
Iteration number 180951
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried
to
allocate 3072 bytes) in /Users/tshaw/Sites/surbl/ptest.php(11) :
runtime-created
function on line 1
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
allocate
3072 bytes) in /Users/tshaw/Sites/surbl/ptest.php(11) : runtime-created
function
on line 1
Test script:
---------------
#!/usr/local/php5/bin/php
<?PHP
// #!/usr/bin/php
error_reporting(E_ALL);
function urlDecodeUnreservedChars( $string ) {
$unreserved = array();
$unreserved[] = dechex( ord( '-' ) );
$unreserved[] = dechex( ord( '.' ) );
$unreserved[] = dechex( ord( '_' ) );
$unreserved[] = dechex( ord( '~' ) );
return preg_replace_callback( array_map( create_function( '$str',
'return "/%" . strtoupper( $str ) . "/x";' ), $unreserved ),
create_function( '$matches', 'return chr( hexdec( $matches[0] ));' ),
$string );
}
for ($i=0; $i <5000000; $i++) {
echo "Iteration number $i\n";
urlDecodeUnreservedChars( "12345" );
}
?>
Expected result:
----------------
Expected it to run to completion
Actual result:
--------------
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried
to
allocate 3072 bytes) in /Users/tshaw/Sites/surbl/ptest.php(11) :
runtime-created
function on line 1
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
allocate
3072 bytes) in /Users/tshaw/Sites/surbl/ptest.php(11) : runtime-created
function
on line 1
--
Edit bug report at https://bugs.php.net/bug.php?id=61792&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=61792&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=61792&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=61792&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=61792&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=61792&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=61792&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=61792&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=61792&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=61792&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=61792&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=61792&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=61792&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=61792&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=61792&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=61792&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=61792&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=61792&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=61792&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=61792&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=61792&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=61792&r=mysqlcfg