Skip to content

Commit f3c50bf

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix leak on double DatePeriod::__construct() call
2 parents 5df5863 + 2d86f8c commit f3c50bf

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

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

68
02 Jul 2026, PHP 8.3.32
79

ext/date/php_date.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4980,6 +4980,23 @@ PHP_METHOD(DatePeriod, createFromISO8601String)
49804980
}
49814981
}
49824982

4983+
static void date_period_reset(php_period_obj *period_obj)
4984+
{
4985+
if (period_obj->start) {
4986+
timelib_time_dtor(period_obj->start);
4987+
}
4988+
if (period_obj->current) {
4989+
timelib_time_dtor(period_obj->current);
4990+
}
4991+
if (period_obj->end) {
4992+
timelib_time_dtor(period_obj->end);
4993+
}
4994+
if (period_obj->interval) {
4995+
timelib_rel_time_dtor(period_obj->interval);
4996+
}
4997+
memset(period_obj, 0, XtOffsetOf(php_period_obj, std));
4998+
}
4999+
49835000
/* {{{ Creates new DatePeriod object. */
49845001
PHP_METHOD(DatePeriod, __construct)
49855002
{
@@ -5001,7 +5018,7 @@ PHP_METHOD(DatePeriod, __construct)
50015018
}
50025019

50035020
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
5004-
dpobj->current = NULL;
5021+
date_period_reset(dpobj);
50055022

50065023
if (isostr) {
50075024
if (!date_period_init_iso8601_string(dpobj, date_ce_date, isostr, isostr_len, options, &recurrences)) {
@@ -5013,6 +5030,7 @@ PHP_METHOD(DatePeriod, __construct)
50135030
if (end) {
50145031
DATE_CHECK_INITIALIZED(Z_PHPDATE_P(end)->time, date_ce_interface);
50155032
}
5033+
DATE_CHECK_INITIALIZED(Z_PHPINTERVAL_P(interval)->initialized, Z_OBJCE_P(interval));
50165034

50175035
/* init */
50185036
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)