Skip to content

Commit 648f16c

Browse files
committed
Fix rel_date leak on DateInterval construction failure
1 parent 2342c06 commit 648f16c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

ext/date/php_date.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,6 +3838,9 @@ static int date_interval_initialize(timelib_rel_time **rt, /*const*/ char *forma
38383838
if (errors->error_count > 0) {
38393839
php_error_docref(NULL, E_WARNING, "Unknown or bad format (%s)", format);
38403840
retval = FAILURE;
3841+
if (p) {
3842+
timelib_rel_time_dtor(p);
3843+
}
38413844
} else {
38423845
if(p) {
38433846
*rt = p;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
DateInterval with bad format should not leak period
3+
--FILE--
4+
<?php
5+
6+
try {
7+
$interval = new DateInterval('P3"D');
8+
} catch (Exception $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
12+
?>
13+
--EXPECT--
14+
DateInterval::__construct(): Unknown or bad format (P3"D)

0 commit comments

Comments
 (0)