]> granicus.if.org Git - php/commitdiff
- MFH: Fixed memory leaks and segfaults, patch by Joe Orton.
authorDerick Rethans <derick@php.net>
Tue, 8 Jul 2008 17:41:51 +0000 (17:41 +0000)
committerDerick Rethans <derick@php.net>
Tue, 8 Jul 2008 17:41:51 +0000 (17:41 +0000)
- MFH: Fixed bug #45038 (Crash when using DateTimeZone object returned by
  Date::getTimezone).

NEWS
ext/date/php_date.c
ext/date/tests/015.phpt [new file with mode: 0644]
ext/date/tests/dateinterval_errors.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index eaa66551fc376a8e28c83ea57c16e4141f7fbd91..94c4ee4492c7358b92523989f0dadc98cde5edba 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -199,6 +199,8 @@ PHP                                                                        NEWS
 
 - Fixed PECL bug #12431 (OCI8 ping functionality is broken). (Oracle Corp.)
 
+- Fixed bug #45038 (Crash when using DateTimeZone object returned by
+  Date::getTimezone). (Joe Orton, Derick)
 - Fixed bug #44769 (declaring private magic methods should throw error). (Felipe)
 - Fixed bug #44913 (Segfault when using return in combination with nested loops
   and continue 2). (Dmitry)
index 2876267dde134c28881668c8e897fa4ad6214a6a..6d6d88c1a2432e7b239dff4124a68e4d46232e08 100644 (file)
@@ -1221,14 +1221,6 @@ PHP_FUNCTION(strtotime)
        timelib_update_ts(t, tzi);
        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) {
-               timelib_tzinfo_dtor(now->tz_info);
-       }
-       if (t->tz_info != tzi) {
-               timelib_tzinfo_dtor(t->tz_info);
-       }
-
        timelib_time_dtor(now);
        timelib_time_dtor(t);
 
@@ -1653,7 +1645,7 @@ static void date_period_it_current_data(zend_object_iterator *iter, zval ***data
                newdateobj->time->tz_abbr = strdup(it_time->tz_abbr);
        }
        if (it_time->tz_info) {
-               newdateobj->time->tz_info = timelib_tzinfo_clone(it_time->tz_info);
+               newdateobj->time->tz_info = it_time->tz_info;
        }
        
        *data = &iterator->current;
@@ -1840,7 +1832,7 @@ static zend_object_value date_object_clone_date(zval *this_ptr TSRMLS_DC)
                new_obj->time->tz_abbr = strdup(old_obj->time->tz_abbr);
        }
        if (old_obj->time->tz_info) {
-               new_obj->time->tz_info = timelib_tzinfo_clone(old_obj->time->tz_info);
+               new_obj->time->tz_info = old_obj->time->tz_info;
        }
        
        return new_ov;
@@ -2053,9 +2045,6 @@ static void date_object_free_storage_date(void *object TSRMLS_DC)
        php_date_obj *intern = (php_date_obj *)object;
 
        if (intern->time) {
-               if (intern->time->tz_info) {
-                       timelib_tzinfo_dtor(intern->time->tz_info);
-               }
                timelib_time_dtor(intern->time);
        }
 
@@ -2088,16 +2077,10 @@ static void date_object_free_storage_period(void *object TSRMLS_DC)
        php_period_obj *intern = (php_period_obj *)object;
 
        if (intern->start) {
-               if (intern->start->tz_info) {
-                       timelib_tzinfo_dtor(intern->start->tz_info);
-               }
                timelib_time_dtor(intern->start);
        }
 
        if (intern->end) {
-               if (intern->end->tz_info) {
-                       timelib_tzinfo_dtor(intern->end->tz_info);
-               }
                timelib_time_dtor(intern->end);
        }
 
@@ -2136,14 +2119,11 @@ static int date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int
        timelib_time   *now;
        timelib_tzinfo *tzi;
        timelib_error_container *err = NULL;
-       int free_tzi = 0, type = TIMELIB_ZONETYPE_ID, new_dst;
+       int type = TIMELIB_ZONETYPE_ID, new_dst;
        char *new_abbr;
        timelib_sll     new_offset;
        
        if (dateobj->time) {
-               if (dateobj->time->tz_info) {
-                       timelib_tzinfo_dtor(dateobj->time->tz_info);
-               }
                timelib_time_dtor(dateobj->time);
        }
        if (format) {
@@ -2171,8 +2151,7 @@ static int date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int
                tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone_object TSRMLS_CC);
                switch (tzobj->type) {
                        case TIMELIB_ZONETYPE_ID:
-                               tzi = timelib_tzinfo_clone(tzobj->tzi.tz);
-                               free_tzi = 1;
+                               tzi = tzobj->tzi.tz;
                                break;
                        case TIMELIB_ZONETYPE_OFFSET:
                                new_offset = tzobj->tzi.utc_offset;
@@ -2185,8 +2164,7 @@ static int date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int
                }
                type = tzobj->type;
        } else if (dateobj->time->tz_info) {
-               tzi = timelib_tzinfo_clone(dateobj->time->tz_info);
-               free_tzi = 1;
+               tzi = dateobj->time->tz_info;
        } else {
                tzi = get_timezone_info(TSRMLS_C);
        }
@@ -2213,12 +2191,6 @@ static int date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int
 
        dateobj->time->have_relative = 0;
 
-       if (type == TIMELIB_ZONETYPE_ID && now->tz_info != tzi) {
-               timelib_tzinfo_dtor(now->tz_info);
-       }
-       if (free_tzi) {
-               timelib_tzinfo_dtor(tzi);
-       }
        timelib_time_dtor(now);
 
        return 1;
@@ -2699,10 +2671,7 @@ PHP_FUNCTION(date_timezone_set)
        if (tzobj->type != TIMELIB_ZONETYPE_ID) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only do this for zones with ID for now");
        }
-       if (dateobj->time->tz_info) {
-               timelib_tzinfo_dtor(dateobj->time->tz_info);
-       }
-       timelib_set_timezone(dateobj->time, timelib_tzinfo_clone(tzobj->tzi.tz));
+       timelib_set_timezone(dateobj->time, tzobj->tzi.tz);
        timelib_unixtime2local(dateobj->time, dateobj->time->sse);
 }
 /* }}} */
@@ -3444,7 +3413,7 @@ PHP_METHOD(DatePeriod, __construct)
                        clone->tz_abbr = strdup(dateobj->time->tz_abbr);
                }
                if (dateobj->time->tz_info) {
-                       clone->tz_info = timelib_tzinfo_clone(dateobj->time->tz_info);
+                       clone->tz_info = dateobj->time->tz_info;
                }
                dpobj->start = clone;
 
@@ -3460,7 +3429,7 @@ PHP_METHOD(DatePeriod, __construct)
                                clone->tz_abbr = strdup(dateobj->time->tz_abbr);
                        }
                        if (dateobj->time->tz_info) {
-                               clone->tz_info = timelib_tzinfo_clone(dateobj->time->tz_info);
+                               clone->tz_info = dateobj->time->tz_info;
                        }
                        dpobj->end = clone;
                }
diff --git a/ext/date/tests/015.phpt b/ext/date/tests/015.phpt
new file mode 100644 (file)
index 0000000..1496d14
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+timezone object reference handling
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+$dto = new DateTime();
+$tzold = $dto->getTimezone();
+var_dump($tzold->getName());
+$dto->setTimezone(new DateTimeZone('US/Eastern'));
+var_dump($tzold->getName());
+var_dump($dto->getTimezone()->getName());
+echo "Done\n";
+?>
+--EXPECTF--
+string(3) "UTC"
+string(3) "UTC"
+string(10) "US/Eastern"
+Done
diff --git a/ext/date/tests/dateinterval_errors.phpt b/ext/date/tests/dateinterval_errors.phpt
new file mode 100644 (file)
index 0000000..505484c
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+DateInterval: Getter and setter errors
+--FILE--
+<?php
+$d = DateInterval::createFromDateString("");
+$d->y = 1984;
+var_dump($d->y);
+var_dump($d->asdf, $d->y);
+?>
+--EXPECTF--
+int(1984)
+
+Fatal error: main(): Unknown property (asdf) in %sdateinterval_errors.php on line 5