From: Stanislav Malyshev Date: Sun, 31 May 2009 21:29:54 +0000 (+0000) Subject: fix for #48247 X-Git-Tag: php-5.4.0alpha1~191^2~3438 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30846e5d0e5ab9d3942de31603230db04e0d3989;p=php fix for #48247 --- diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 78349c92bd..8c95f6bccf 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -597,6 +597,7 @@ static PHP_GINIT_FUNCTION(date) { date_globals->default_timezone = NULL; date_globals->timezone = NULL; + date_globals->tzcache = NULL; } /* }}} */ @@ -615,7 +616,7 @@ PHP_RINIT_FUNCTION(date) efree(DATEG(timezone)); } DATEG(timezone) = NULL; - zend_hash_init(&DATEG(tzcache), 4, NULL, _php_date_tzinfo_dtor, 0); + DATEG(tzcache) = NULL; return SUCCESS; } @@ -628,8 +629,11 @@ PHP_RSHUTDOWN_FUNCTION(date) efree(DATEG(timezone)); } DATEG(timezone) = NULL; - zend_hash_destroy(&DATEG(tzcache)); - + if(DATEG(tzcache)) { + zend_hash_destroy(DATEG(tzcache)); + FREE_HASHTABLE(DATEG(tzcache)); + DATEG(tzcache) = NULL; + } return SUCCESS; } /* }}} */ @@ -811,13 +815,18 @@ static timelib_tzinfo *php_date_parse_tzfile(char *formal_tzname, const timelib_ { timelib_tzinfo *tzi, **ptzi; - if (zend_hash_find(&DATEG(tzcache), formal_tzname, strlen(formal_tzname) + 1, (void **) &ptzi) == SUCCESS) { + if(!DATEG(tzcache)) { + ALLOC_HASHTABLE(DATEG(tzcache)); + zend_hash_init(DATEG(tzcache), 4, NULL, _php_date_tzinfo_dtor, 0); + } + + if (zend_hash_find(DATEG(tzcache), formal_tzname, strlen(formal_tzname) + 1, (void **) &ptzi) == SUCCESS) { return *ptzi; } tzi = timelib_parse_tzfile(formal_tzname, tzdb); if (tzi) { - zend_hash_add(&DATEG(tzcache), formal_tzname, strlen(formal_tzname) + 1, (void *) &tzi, sizeof(timelib_tzinfo*), NULL); + zend_hash_add(DATEG(tzcache), formal_tzname, strlen(formal_tzname) + 1, (void *) &tzi, sizeof(timelib_tzinfo*), NULL); } return tzi; } @@ -906,7 +915,7 @@ PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D) { char *tz; timelib_tzinfo *tzi; - + tz = guess_timezone(DATE_TIMEZONEDB TSRMLS_CC); tzi = php_date_parse_tzfile(tz, DATE_TIMEZONEDB TSRMLS_CC); if (! tzi) { diff --git a/ext/date/php_date.h b/ext/date/php_date.h index f8fab46f51..12824a2311 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -153,7 +153,7 @@ struct _php_period_obj { ZEND_BEGIN_MODULE_GLOBALS(date) char *default_timezone; char *timezone; - HashTable tzcache; + HashTable *tzcache; timelib_error_container *last_errors; ZEND_END_MODULE_GLOBALS(date)