php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43206 date_timezone_get() leaks memory
Submitted: 2007-11-06 17:40 UTC Modified: 2008-07-08 18:07 UTC
Votes:13
Avg. Score:4.9 ± 0.3
Reproduced:12 of 12 (100.0%)
Same Version:3 (25.0%)
Same OS:5 (41.7%)
From: thekid@php.net Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.2.5RC2 OS: Any
Private report: No CVE-ID: None
 [2007-11-06 17:40 UTC] thekid@php.net
Description:
------------
date_timezone_get() leaks memory

Reproduce code:
---------------
<?php
  $d= date_create('now');
  while(TRUE) {
    date_timezone_get($d);
  }
?>


Expected result:
----------------
Memory usage stays constant.

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-06 17:42 UTC] thekid@php.net
The following patch fixes the problem:

== 
$ cvs diff -u ext/date/
cvs diff: Diffing ext/date
Index: ext/date/php_date.c
===================================================================
RCS file: /repository/php-src/ext/date/php_date.c,v
retrieving revision 1.43.2.45.2.51
diff -u -r1.43.2.45.2.51 php_date.c
--- ext/date/php_date.c 12 Jul 2007 18:59:05 -0000      1.43.2.45.2.51
+++ ext/date/php_date.c 6 Nov 2007 17:40:24 -0000
@@ -1613,7 +1613,7 @@
 static void date_object_free_storage_timezone(void *object TSRMLS_DC)
 {
        php_timezone_obj *intern = (php_timezone_obj *)object;
-
+       timelib_tzinfo_dtor(intern->tz);
        zend_object_std_dtor(&intern->std TSRMLS_CC);
        efree(object);
 }
cvs diff: Diffing ext/date/lib
cvs diff: Diffing ext/date/tests

== 
Seems it was simply forgotten to free the timezone in DateTimeZone's destructor.

Because ->tz is an internal pointer (and not a zval) memory_get_usage() will not report a memory increase, you'll have to use Task Manager / top / ps to see the effect
 [2008-07-08 18:07 UTC] derick@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 29 10:00:02 2025 UTC