[php-src] master: Merge branch 'PHP-8.2' into PHP-8.3

Ilija Tovilo <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Ilija Tovilo (iluuu1994)
Date: 2026-07-15T20:39:51+02:00

Commit: https://github.com/php/php-src/commit/f3c50bfb1bc032758b1af2e30776abf1a18c866d
Raw diff: https://github.com/php/php-src/commit/f3c50bfb1bc032758b1af2e30776abf1a18c866d.diff

Merge branch 'PHP-8.2' into PHP-8.3

* PHP-8.2:
  Fix leak on double DatePeriod::__construct() call

Changed paths:
  A  ext/date/tests/DatePeriod_double_constructor_call.phpt
  M  NEWS
  M  ext/date/php_date.c


Diff:

diff --git a/NEWS b/NEWS
index 3bebd2660a2a..03a3f4f89f7a 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? ????, PHP 8.3.33
 
+- Date:
+  . Fixed leak on double DatePeriod::__construct() call. (ilutov)
 
 02 Jul 2026, PHP 8.3.32
 
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 84fad72948fd..a74317bd95cd 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -4980,6 +4980,23 @@ PHP_METHOD(DatePeriod, createFromISO8601String)
 	}
 }
 
+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)
 {
@@ -5001,7 +5018,7 @@ PHP_METHOD(DatePeriod, __construct)
 	}
 
 	dpobj = Z_PHPPERIOD_P(ZEND_THIS);
-	dpobj->current = NULL;
+	date_period_reset(dpobj);
 
 	if (isostr) {
 		if (!date_period_init_iso8601_string(dpobj, date_ce_date, isostr, isostr_len, options, &recurrences)) {
@@ -5013,6 +5030,7 @@ PHP_METHOD(DatePeriod, __construct)
 		if (end) {
 			DATE_CHECK_INITIALIZED(Z_PHPDATE_P(end)->time, date_ce_interface);
 		}
+		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 000000000000..551d2727282d
--- /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===
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.