]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #46108 (DateTime - Memory leak when unserializing)
authorFelipe Pena <felipe@php.net>
Tue, 7 Apr 2009 20:05:50 +0000 (20:05 +0000)
committerFelipe Pena <felipe@php.net>
Tue, 7 Apr 2009 20:05:50 +0000 (20:05 +0000)
NEWS
ext/date/php_date.c
ext/date/tests/bug46108.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 2322e0320c8ac17012f251bdae30b26f2a5fd965..0d5c1a0d4ad642df08922b3c5fd4d8f9ebf2764f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,7 @@ PHP                                                                        NEWS
 - Fixed bug #47516 (nowdoc can not be embed in heredoc but can be embed in
   double quote). (Dmitry)
 - Fixed bug #47038 (Memory leak in include). (Dmitry)
+- Fixed bug #46108 (DateTime - Memory leak when unserializing). (Felipe)
 - Fixed bug #44861 (scrollable cursor don't work with pgsql). (Matteo)
 - Fixed bug #44409 (PDO::FETCH_SERIALIZE calls __construct()). (Matteo)
 - Fixed bug #44173 (PDO->query() parameter parsing/checking needs an 
index 62a65e6546c68478ef44247818c67624313732ea..82db083317c409c25ac253f7ee1f8150d7e288c4 100644 (file)
@@ -2268,10 +2268,6 @@ static void date_object_free_storage_period(void *object TSRMLS_DC)
 /* Advanced Interface */
 static zval * date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC)
 {
-       if (!object) {
-               ALLOC_ZVAL(object);
-       }
-
        Z_TYPE_P(object) = IS_OBJECT;
        object_init_ex(object, pce);
        Z_SET_REFCOUNT_P(object, 1);
@@ -2461,12 +2457,14 @@ static int php_date_initialize_from_hash(zval **return_value, php_date_obj **dat
 
                                                tzi = php_date_parse_tzfile(Z_STRVAL_PP(z_timezone), DATE_TIMEZONEDB TSRMLS_CC);
 
+                                               ALLOC_INIT_ZVAL(tmp_obj);
                                                tzobj = zend_object_store_get_object(date_instantiate(date_ce_timezone, tmp_obj TSRMLS_CC) TSRMLS_CC);
                                                tzobj->type = TIMELIB_ZONETYPE_ID;
                                                tzobj->tzi.tz = tzi;
                                                tzobj->initialized = 1;
 
                                                date_initialize(*dateobj, Z_STRVAL_PP(z_date), Z_STRLEN_PP(z_date), NULL, tmp_obj, 0 TSRMLS_CC);
+                                               zval_ptr_dtor(&tmp_obj);
                                                return 1;
                                }
                        }
diff --git a/ext/date/tests/bug46108.phpt b/ext/date/tests/bug46108.phpt
new file mode 100644 (file)
index 0000000..12fdfa7
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Bug #46108 (DateTime - Memory leak when unserializing)
+--FILE--
+<?php
+
+date_default_timezone_set('America/Sao_Paulo');
+
+var_dump(unserialize(serialize(new Datetime)));
+
+?>
+--EXPECTF--
+object(DateTime)#%d (3) {
+  [%u|b%"date"]=>
+  %string|unicode%(%d) "%s"
+  [%u|b%"timezone_type"]=>
+  int(%d)
+  [%u|b%"timezone"]=>
+  %string|unicode%(%d) "America/Sao_Paulo"
+}