php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67686 date_create_from_format memory leak
Submitted: 2014-07-25 19:17 UTC Modified: 2020-11-15 04:22 UTC
From: alex at iplenix dot com Assigned: cmb (profile)
Status: No Feedback Package: Date/time related
PHP Version: 5.5.15 OS: windows 8.2 and centos 6.5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
46 + 20 = ?
Subscribe to this entry?

 
 [2014-07-25 19:17 UTC] alex at iplenix dot com
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
I cannot reproduce this with current PHP-7.3.  Does this still
happen to you with any of the actively supported PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2020-11-15 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC