summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-08-27 12:54:43 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-08-27 12:54:43 +0200
commit988fc94bbbfb44a63ef5aeb745d38c1a73e2db0f (patch)
tree2fc7a9025b63ba3bc188cc630b4056532a46ec0a /ext
parent614c0b846eea59840977900d0e91562301aa4c0e (diff)
downloadphp-git-988fc94bbbfb44a63ef5aeb745d38c1a73e2db0f.tar.gz
Fix leak on failed DatePeriod initialization
We need to free not only p here, but also b and e.
Diffstat (limited to 'ext')
-rw-r--r--ext/date/php_date.c6
-rw-r--r--ext/date/tests/date_interval_bad_format_leak.phpt7
2 files changed, 13 insertions, 0 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 0892439a06..43aa2ba637 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -4077,6 +4077,12 @@ static int date_period_initialize(timelib_time **st, timelib_time **et, timelib_
if (errors->error_count > 0) {
php_error_docref(NULL, E_WARNING, "Unknown or bad format (%s)", format);
retval = FAILURE;
+ if (b) {
+ timelib_time_dtor(b);
+ }
+ if (e) {
+ timelib_time_dtor(e);
+ }
if (p) {
timelib_rel_time_dtor(p);
}
diff --git a/ext/date/tests/date_interval_bad_format_leak.phpt b/ext/date/tests/date_interval_bad_format_leak.phpt
index d15bf57b3f..da6982c9be 100644
--- a/ext/date/tests/date_interval_bad_format_leak.phpt
+++ b/ext/date/tests/date_interval_bad_format_leak.phpt
@@ -15,7 +15,14 @@ try {
echo $e->getMessage(), "\n";
}
+try {
+ new DatePeriod('2008-03-01T12:00:00Z1');
+} catch (Exception $e) {
+ echo $e->getMessage(), "\n";
+}
+
?>
--EXPECT--
DateInterval::__construct(): Unknown or bad format (P3"D)
DatePeriod::__construct(): Unknown or bad format (P3"D)
+DatePeriod::__construct(): Unknown or bad format (2008-03-01T12:00:00Z1)