]> granicus.if.org Git - php/commitdiff
- Change memory management so that tzinfo structures can live outside time
authorDerick Rethans <derick@php.net>
Tue, 5 Jul 2005 18:30:30 +0000 (18:30 +0000)
committerDerick Rethans <derick@php.net>
Tue, 5 Jul 2005 18:30:30 +0000 (18:30 +0000)
  structures too.

ext/date/lib/timelib.c
ext/date/php_date.c

index 576b2e2efcd2b38e2dc60e1e766791b3fe48e07b..eae26aba84d53430bac8467cd48ba77e5e44b497 100644 (file)
@@ -49,10 +49,6 @@ void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr)
 void timelib_time_dtor(timelib_time* t)
 {
        TIMELIB_TIME_FREE(t->tz_abbr);
-       if (t->tz_info) {
-               timelib_tzinfo_dtor(t->tz_info);
-               t->tz_info = NULL;
-       }
        TIMELIB_TIME_FREE(t);
 }
 
index 9bf2ac9e27e4c97da4b58bd15a7a27b34a01a23b..689e05fc92a8002d83aeb2c27f0b37ffd463f200 100644 (file)
@@ -361,6 +361,9 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
        string = php_format_date(format, format_len, t, localtime);
        
        RETVAL_STRING(string, 0);
+       if (localtime) {
+               timelib_tzinfo_dtor(tzi);
+       }
        timelib_time_dtor(t);
 }
 /* }}} */
@@ -440,16 +443,16 @@ PHP_FUNCTION(strtotime)
        ts = timelib_date_to_int(t, &error2);
 
        /* if tz_info is not a copy, avoid double free */
-       if (now->tz_info == tzi) {
-               now->tz_info = NULL;
+       if (now->tz_info != tzi) {
+               timelib_tzinfo_dtor(now->tz_info);
        }
-       if (t->tz_info == tzi) {
-               t->tz_info = NULL;
+       if (t->tz_info != tzi) {
+               timelib_tzinfo_dtor(t->tz_info);
        }
 
+       timelib_tzinfo_dtor(tzi);
        timelib_time_dtor(now); 
        timelib_time_dtor(t);
-       timelib_tzinfo_dtor(tzi);
 
        if (error1 || error2) {
                RETURN_FALSE;
@@ -535,8 +538,10 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
        /* Clean up and return */
        ts = timelib_date_to_int(now, &error);
        ts += adjust_seconds;
-
        timelib_time_dtor(now);
+       if (!gmt) {
+               timelib_tzinfo_dtor(tzi);
+       }
 
        if (error) {
                RETURN_FALSE;
@@ -729,6 +734,7 @@ PHP_FUNCTION(localtime)
                add_next_index_long(return_value, ts->dst);
        }
 
+       timelib_tzinfo_dtor(tzi);
        timelib_time_dtor(ts);
 }
 /* }}} */
@@ -763,6 +769,7 @@ PHP_FUNCTION(getdate)
        add_assoc_string(return_value, "month", mon_full_names[ts->m - 1], 1);
        add_index_long(return_value, 0, timestamp);
 
+       timelib_tzinfo_dtor(tzi);
        timelib_time_dtor(ts);
 }
 /* }}} */