Commit 2d86f8cf489 for php.net
commit 2d86f8cf489ea5410edd19d301c1aefe330599ab
Author: Ilija Tovilo <ilija.tovilo@me.com>
Date: Tue Jul 7 20:32:58 2026 +0200
Fix leak on double DatePeriod::__construct() call
Closes GH-22643
diff --git a/NEWS b/NEWS
index 12ae8c0fb23..e9e5b76cea6 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.2.33
+- Date:
+ . Fixed leak on double DatePeriod::__construct() call. (ilutov)
02 Jul 2026, PHP 8.2.32
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 9108a7c246a..c71cef2cf15 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -4720,6 +4720,23 @@ static bool date_period_initialize(timelib_time **st, timelib_time **et, timelib
return retval;
} /* }}} */
+static void date_period_reset(php_period_obj *period_obj)
+{
+ if (period_obj->start) {
+ timelib_time_dtor(period_obj->start);
+ }
+ if (period_obj->current) {
+ timelib_time_dtor(period_obj->current);
+ }
+ if (period_obj->end) {
+ timelib_time_dtor(period_obj->end);
+ }
+ if (period_obj->interval) {
+ timelib_rel_time_dtor(period_obj->interval);
+ }
+ memset(period_obj, 0, XtOffsetOf(php_period_obj, std));
+}
+
/* {{{ Creates new DatePeriod object. */
PHP_METHOD(DatePeriod, __construct)
{
@@ -4741,7 +4758,7 @@ PHP_METHOD(DatePeriod, __construct)
}
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
- dpobj->current = NULL;
+ date_period_reset(dpobj);
if (isostr) {
if (!date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len)) {
@@ -4780,6 +4797,7 @@ PHP_METHOD(DatePeriod, __construct)
if (end) {
DATE_CHECK_INITIALIZED(Z_PHPDATE_P(end)->time, DateTimeInterface);
}
+ DATE_CHECK_INITIALIZED(Z_PHPINTERVAL_P(interval)->initialized, Z_OBJCE_P(interval));
/* init */
php_interval_obj *intobj = Z_PHPINTERVAL_P(interval);
diff --git a/ext/date/tests/DatePeriod_double_constructor_call.phpt b/ext/date/tests/DatePeriod_double_constructor_call.phpt
new file mode 100644
index 00000000000..551d2727282
--- /dev/null
+++ b/ext/date/tests/DatePeriod_double_constructor_call.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Double DatePeriod::__construct() call
+--FILE--
+<?php
+
+$start = new \DateTime();
+$interval = new \DateInterval('P1D');
+$period = new \DatePeriod($start, $interval, 1);
+$period->__construct($start, $interval, 1);
+
+?>
+===DONE===
+--EXPECT--
+===DONE===