From: Felipe Pena Date: Tue, 7 Apr 2009 20:05:50 +0000 (+0000) Subject: - MFH: Fixed bug #46108 (DateTime - Memory leak when unserializing) X-Git-Tag: php-5.3.0RC2~200 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b33f88607af5f957b13fcad0c61fe96a4d3b5697;p=php - MFH: Fixed bug #46108 (DateTime - Memory leak when unserializing) --- diff --git a/NEWS b/NEWS index 2322e0320c..0d5c1a0d4a 100644 --- 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 diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 62a65e6546..82db083317 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -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 index 0000000000..12fdfa7e5d --- /dev/null +++ b/ext/date/tests/bug46108.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #46108 (DateTime - Memory leak when unserializing) +--FILE-- + +--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" +}