derick          Tue Jul  8 17:40:35 2008 UTC

  Added files:                 
    /php-src/ext/date/tests     015.phpt dateinterval_errors.phpt 

  Modified files:              
    /php-src/ext/date   php_date.c 
  Log:
  - Fixed memory leaks and segfaults, patch by Joe Orton.
  - Fixed bug #45038 (Crash when using DateTimeZone object returned by
    Date::getTimezone).
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.189&r2=1.190&diff_format=u
Index: php-src/ext/date/php_date.c
diff -u php-src/ext/date/php_date.c:1.189 php-src/ext/date/php_date.c:1.190
--- php-src/ext/date/php_date.c:1.189   Sat Jun  7 22:41:02 2008
+++ php-src/ext/date/php_date.c Tue Jul  8 17:40:34 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_date.c,v 1.189 2008/06/07 22:41:02 tony2001 Exp $ */
+/* $Id: php_date.c,v 1.190 2008/07/08 17:40:34 derick Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -1341,14 +1341,6 @@
        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);
 
@@ -1779,7 +1771,7 @@
                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;
@@ -1966,7 +1958,7 @@
                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;
@@ -2185,9 +2177,6 @@
        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);
        }
 
@@ -2220,16 +2209,10 @@
        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);
        }
 
@@ -2268,14 +2251,11 @@
        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) {
@@ -2303,8 +2283,7 @@
                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;
@@ -2317,8 +2296,7 @@
                }
                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);
        }
@@ -2345,12 +2323,6 @@
 
        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;
@@ -2860,10 +2832,7 @@
        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);
 }
 /* }}} */
@@ -3613,7 +3582,7 @@
                        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;
 
@@ -3629,7 +3598,7 @@
                                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;
                }

http://cvs.php.net/viewvc.cgi/php-src/ext/date/tests/015.phpt?view=markup&rev=1.1
Index: php-src/ext/date/tests/015.phpt
+++ php-src/ext/date/tests/015.phpt
--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--
unicode(3) "UTC"
unicode(3) "UTC"
unicode(10) "US/Eastern"
Done

http://cvs.php.net/viewvc.cgi/php-src/ext/date/tests/dateinterval_errors.phpt?view=markup&rev=1.1
Index: php-src/ext/date/tests/dateinterval_errors.phpt
+++ php-src/ext/date/tests/dateinterval_errors.phpt
--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



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to