Skip to content

Commit 2d86f8c

Browse files
committed
Fix leak on double DatePeriod::__construct() call
Closes GH-22643
1 parent 6f1beed commit 2d86f8c

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.2.33
44

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

68
02 Jul 2026, PHP 8.2.32
79

ext/date/php_date.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4720,6 +4720,23 @@ static bool date_period_initialize(timelib_time **st, timelib_time **et, timelib
47204720
return retval;
47214721
} /* }}} */
47224722

4723+
static void date_period_reset(php_period_obj *period_obj)
4724+
{
4725+
if (period_obj->start) {
4726+
timelib_time_dtor(period_obj->start);
4727+
}
4728+
if (period_obj->current) {
4729+
timelib_time_dtor(period_obj->current);
4730+
}
4731+
if (period_obj->end) {
4732+
timelib_time_dtor(period_obj->end);
4733+
}
4734+
if (period_obj->interval) {
4735+
timelib_rel_time_dtor(period_obj->interval);
4736+
}
4737+
memset(period_obj, 0, XtOffsetOf(php_period_obj, std));
4738+
}
4739+
47234740
/* {{{ Creates new DatePeriod object. */
47244741
PHP_METHOD(DatePeriod, __construct)
47254742
{
@@ -4741,7 +4758,7 @@ PHP_METHOD(DatePeriod, __construct)
47414758
}
47424759

47434760
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
4744-
dpobj->current = NULL;
4761+
date_period_reset(dpobj);
47454762

47464763
if (isostr) {
47474764
if (!date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len)) {
@@ -4780,6 +4797,7 @@ PHP_METHOD(DatePeriod, __construct)
47804797
if (end) {
47814798
DATE_CHECK_INITIALIZED(Z_PHPDATE_P(end)->time, DateTimeInterface);
47824799
}
4800+
DATE_CHECK_INITIALIZED(Z_PHPINTERVAL_P(interval)->initialized, Z_OBJCE_P(interval));
47834801

47844802
/* init */
47854803
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)