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: -
From: alex at iplenix dot com Assigned:
Status: Open 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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alex at iplenix dot com
New email:
PHP Version: OS:

 

 [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

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Aug 10 18:01:25 2020 UTC