Skip to content

Commit 0dbedb3

Browse files
committed
Fixed memory leaks with DatePeriod::__unserialise
1 parent 09237f6 commit 0dbedb3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ext/date/php_date.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5077,6 +5077,9 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
50775077
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
50785078
php_date_obj *date_obj;
50795079
date_obj = Z_PHPDATE_P(ht_entry);
5080+
if (period_obj->start != NULL) {
5081+
timelib_time_dtor(period_obj->start);
5082+
}
50805083
period_obj->start = timelib_time_clone(date_obj->time);
50815084
period_obj->start_ce = Z_OBJCE_P(ht_entry);
50825085
} else if (Z_TYPE_P(ht_entry) != IS_NULL) {
@@ -5091,6 +5094,9 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
50915094
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
50925095
php_date_obj *date_obj;
50935096
date_obj = Z_PHPDATE_P(ht_entry);
5097+
if (period_obj->end != NULL) {
5098+
timelib_time_dtor(period_obj->end);
5099+
}
50945100
period_obj->end = timelib_time_clone(date_obj->time);
50955101
} else if (Z_TYPE_P(ht_entry) != IS_NULL) {
50965102
return 0;
@@ -5104,6 +5110,9 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
51045110
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
51055111
php_date_obj *date_obj;
51065112
date_obj = Z_PHPDATE_P(ht_entry);
5113+
if (period_obj->current != NULL) {
5114+
timelib_time_dtor(period_obj->current);
5115+
}
51075116
period_obj->current = timelib_time_clone(date_obj->time);
51085117
} else if (Z_TYPE_P(ht_entry) != IS_NULL) {
51095118
return 0;
@@ -5117,6 +5126,9 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
51175126
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_interval) {
51185127
php_interval_obj *interval_obj;
51195128
interval_obj = Z_PHPINTERVAL_P(ht_entry);
5129+
if (period_obj->interval != NULL) {
5130+
timelib_rel_time_dtor(period_obj->interval);
5131+
}
51205132
period_obj->interval = timelib_rel_time_clone(interval_obj->diff);
51215133
} else { /* interval is required */
51225134
return 0;

0 commit comments

Comments
 (0)