Bug #67686 [NEW]: date_create_from_format memory leak
| From: | alex at iplenix dot com | Date: | Fri, 25 Jul 2014 19:17:28 +0000 |
| Subject: | Bug #67686 [NEW]: date_create_from_format memory leak | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-186816@lists.php.net to get a copy of this message | ||
From: alex at iplenix dot com
Operating system: windows 8.2 and centos 6.5
PHP version: 5.5.15
Package: Date/time related
Bug Type: Bug
Bug description:date_create_from_format memory leak
Description:
------------
function date_create_from_format leak memory when returns false.
Test script:
---------------
<?php
define('PHP_ERROR_REPORTING',E_ALL);
// Coloca no diretorio do binario e dai todos as indirecoes funcionam
chdir( dirname ( __FILE__ ) );
main_teste_memoria();
function iplx_echo_memuse($msg){
$m1=memory_get_usage();
$m2=memory_get_usage(true);
echo "$msg php($m1) system($m2)\n";
}
function test_date_create_from_format($ts='20140530140000'){
$date = date_create_from_format('d-m-Y H:i:s', $ts, new
DateTimeZone('UTC'));
// $date = date_create_from_format('Y-m-d H:i:s', $ts, new
DateTimeZone('UTC'));
// $date = date_create_from_format('YmdHis.u', $ts, new
DateTimeZone('UTC'));
// $date = date_create_from_format('YmdHis.s', $ts, new
DateTimeZone('UTC'));
// $date = date_create_from_format('d/m/y H:i:s', $ts, new
DateTimeZone('UTC'));
$date = date_create_from_format('YmdHis', $ts, new
DateTimeZone('UTC'));
for($i=0;$i<100;++$i){
$date->modify('+1 minute');
$ts=$date->format('YmdHis');
$date = date_create_from_format('YmdHis', $ts, new
DateTimeZone('UTC'));
}
}
function main_teste_memoria(){
$ts = '20140530140000';
$counting = 1;
$oldLimit = ini_get("memory_limit");
echo "Current memory limit $oldLimit \n";
ini_set("memory_limit", "1M");
$oldLimit = ini_get("memory_limit");
gc_enable(); // enable memory management
echo "Current memory limit $oldLimit \n";
while(true){
iplx_echo_memuse("Before test_date_create_from_format");
test_date_create_from_format($ts);
$counting++;
iplx_echo_memuse("After test_date_create_from_format");
echo "Executions ($counting) \n";
}
}
?>
Actual result:
--------------
Executing on Windows 8.1, PHP 5.5.15 the result after some seconds is
this crash.
> php test_date_create_from_format.php
...
Executions (8188)
Before test_date_create_from_format php(614928) system(1048576)
After test_date_create_from_format php(614960) system(1048576)
Executions (8189)
Before test_date_create_from_format php(614960) system(1048576)
PHP Fatal error: Allowed memory size of 1048576 bytes exhausted (tried
to allocate 524288 bytes) in
X:\Iplenix_Fontes\mtx-gateway\gw-www\client-side\BirtechVirtualModem\bin\test_date_create_from_format.php
on line 26
==============================================================================
On centos 6.5 64bits, PHP 5.4.29 the result is very similar.
$ php test_date_create_from_format.php
...
Executions (4090)
Before test_date_create_from_format php(692288) system(1048576)
After test_date_create_from_format php(692352) system(1048576)
Executions (4091)
Before test_date_create_from_format php(692352) system(1048576)
After test_date_create_from_format php(692416) system(1048576)
Executions (4092)
Before test_date_create_from_format php(692416) system(1048576)
After test_date_create_from_format php(692480) system(1048576)
Executions (4093)
Before test_date_create_from_format php(692480) system(1048576)
PHP Fatal error: Allowed memory size of 1048576 bytes exhausted (tried
to allocate 524288 bytes) in
/var/iplenix/mtx-gateway/gw-www/client-side/BirtechVirtualModem/bin/test_date_create_from_format.php
on line 26
--
Edit bug report at https://bugs.php.net/bug.php?id=67686&edit=1
--