From: Stanislav Malyshev Date: Sun, 31 May 2009 20:43:57 +0000 (+0000) Subject: fix for #48247 X-Git-Tag: php-5.2.10RC2~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc4bfd4d800b440de611187bc907ca49dffd46b0;p=php fix for #48247 --- diff --git a/ext/date/php_date.c b/ext/date/php_date.c index d01394bc92..fa3f449fa7 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -343,6 +343,7 @@ static PHP_GINIT_FUNCTION(date) { date_globals->default_timezone = NULL; date_globals->timezone = NULL; + date_globals->tzcache = NULL; } /* }}} */ @@ -361,7 +362,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; } @@ -374,8 +375,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; } /* }}} */ @@ -552,13 +556,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; } @@ -654,7 +663,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 4d83988303..9a25f62a0e 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -87,7 +87,7 @@ PHP_MINFO_FUNCTION(date); ZEND_BEGIN_MODULE_GLOBALS(date) char *default_timezone; char *timezone; - HashTable tzcache; + HashTable *tzcache; ZEND_END_MODULE_GLOBALS(date) #ifdef ZTS