Skip to content

Commit 0fbd104

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix leak on double DatePeriod::__construct() call
2 parents 923814c + f3c50bf commit 0fbd104

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.4.24
44

5+
- Date:
6+
. Fixed leak on double DatePeriod::__construct() call. (ilutov)
57

68
30 Jul 2026, PHP 8.4.24
79

ext/date/php_date.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5226,6 +5226,23 @@ PHP_METHOD(DatePeriod, createFromISO8601String)
52265226
}
52275227
}
52285228

5229+
static void date_period_reset(php_period_obj *period_obj)
5230+
{
5231+
if (period_obj->start) {
5232+
timelib_time_dtor(period_obj->start);
5233+
}
5234+
if (period_obj->current) {
5235+
timelib_time_dtor(period_obj->current);
5236+
}
5237+
if (period_obj->end) {
5238+
timelib_time_dtor(period_obj->end);
5239+
}
5240+
if (period_obj->interval) {
5241+
timelib_rel_time_dtor(period_obj->interval);
5242+
}
5243+
memset(period_obj, 0, XtOffsetOf(php_period_obj, std));
5244+
}
5245+
52295246
/* {{{ Creates new DatePeriod object. */
52305247
PHP_METHOD(DatePeriod, __construct)
52315248
{
@@ -5247,7 +5264,7 @@ PHP_METHOD(DatePeriod, __construct)
52475264
}
52485265

52495266
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
5250-
dpobj->current = NULL;
5267+
date_period_reset(dpobj);
52515268

52525269
if (isostr) {
52535270
zend_error(E_DEPRECATED, "Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, "
@@ -5265,6 +5282,7 @@ PHP_METHOD(DatePeriod, __construct)
52655282
if (end) {
52665283
DATE_CHECK_INITIALIZED(Z_PHPDATE_P(end)->time, date_ce_interface);
52675284
}
5285+
DATE_CHECK_INITIALIZED(Z_PHPINTERVAL_P(interval)->initialized, Z_OBJCE_P(interval));
52685286

52695287
/* init */
52705288
php_interval_obj *intobj = Z_PHPINTERVAL_P(interval);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Double DatePeriod::__construct() call
3+
--FILE--
4+
<?php
5+
6+
$start = new \DateTime();
7+
$interval = new \DateInterval('P1D');
8+
$period = new \DatePeriod($start, $interval, 1);
9+
$period->__construct($start, $interval, 1);
10+
11+
?>
12+
===DONE===
13+
--EXPECT--
14+
===DONE===

0 commit comments

Comments
 (0)