|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-11-05 15:44 UTC] cmb@php.net
-Status: Open
+Status: Feedback
-Assigned To:
+Assigned To: cmb
[2020-11-05 15:44 UTC] cmb@php.net
[2020-11-15 04:22 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 18:00:01 2025 UTC |
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