php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41911 Passing string encapsulated in SimpleXMLElement to strtotime causes memory leak
Submitted: 2007-07-06 06:06 UTC Modified: 2007-07-06 09:51 UTC
From: irb at redwoodtech dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.3 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2007-07-06 06:06 UTC] irb at redwoodtech dot com
Description:
------------
If a time string is to be read from a SimpleXML object and converted into a unix timestamp then a memory leak occurs if the SimpleXML object is passed directly to strtotime.

The memory leak can be stopped by type casting before passing the string to strtotime. For example, change the relevant line in the reproduce code to:

$lTime = strtotime ((string) $xml['timestamp']);

Reproduce code:
---------------
while(true)
{
	$xml = new SimpleXMLElement('<test timestamp="Thu, 5 Jul 2007 16:51:23 GMT"></test>');
	echo 'Current Daemon Memory Usage is ' . memory_get_usage ( ) ." bytes : Before STRTOTIME\n";
	$lTime = strtotime ($xml['timestamp']);
	echo 'Current Daemon Memory Usage is ' . memory_get_usage ( ) ." bytes : After STRTOTIME\n";
}

Expected result:
----------------
The following is expected. The point being that the memory usage of the application is constant.

Current Daemon Memory Usage is 53720 bytes : Before STRTOTIME
Current Daemon Memory Usage is 53720 bytes : After STRTOTIME
Current Daemon Memory Usage is 53720 bytes : Before STRTOTIME
Current Daemon Memory Usage is 53720 bytes : After STRTOTIME
Current Daemon Memory Usage is 53720 bytes : Before STRTOTIME
Current Daemon Memory Usage is 53720 bytes : After STRTOTIME

Actual result:
--------------
Memory usage increases over time.

Current Daemon Memory Usage is ___94240 bytes : After STRTOTIME
Current Daemon Memory Usage is ___94400 bytes : Before STRTOTIME
Current Daemon Memory Usage is ___94440 bytes : After STRTOTIME
Current Daemon Memory Usage is ___94600 bytes : Before STRTOTIME
Current Daemon Memory Usage is ___94640 bytes : After STRTOTIME
Current Daemon Memory Usage is ___94800 bytes : Before STRTOTIME
Current Daemon Memory Usage is ___94840 bytes : After STRTOTIME

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-06 09:20 UTC] tony2001@php.net
All memory leaks are reported by the engine, this is the way the engine works and it is perfectly acceptable.
 [2007-07-06 09:51 UTC] irb at redwoodtech dot com
Tony, thanks for the quick response.

The messages being logged are generated by my own debug code (See the echo statements in the reproduce code). Unless I've misunderstood your comment, you've mistaken my debug messages for the memory leak alerts raised by the engine.

I didn't mean for the issue raised to be the way in which the memory leak is reported but rather the memory leak itself.

I asked someone on irc.freenode.net#php to double check my reasoning and they told me that this looks bogus but for a different reason - that PHP isn't designed for long-term processes. Is that right?

Any clarification you could provide would be very much appreciated.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 20 20:03:35 2022 UTC