]> granicus.if.org Git - php/commitdiff
fix for #48247
authorStanislav Malyshev <stas@php.net>
Sun, 31 May 2009 21:28:38 +0000 (21:28 +0000)
committerStanislav Malyshev <stas@php.net>
Sun, 31 May 2009 21:28:38 +0000 (21:28 +0000)
ext/date/php_date.c
ext/date/php_date.h

index 35d24430e9392aff13d4dc65acae449bfe92928e..a52188f88b436e49179b8453d35dc42f24d93398 100644 (file)
@@ -590,6 +590,7 @@ static PHP_GINIT_FUNCTION(date)
 {
        date_globals->default_timezone = NULL;
        date_globals->timezone = NULL;
+       date_globals->tzcache = NULL;
 }
 /* }}} */
 
@@ -608,7 +609,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;
 }
@@ -621,8 +622,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;
 }
 /* }}} */
@@ -804,13 +808,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) {
index 93518a3a6b625c3f12317c1503a280b36b80cfe7..a98b2d521a4ea844e23172b7caeb215eb99c363b 100644 (file)
@@ -149,7 +149,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)