From 988fc94bbbfb44a63ef5aeb745d38c1a73e2db0f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 27 Aug 2020 12:54:43 +0200 Subject: [PATCH] Fix leak on failed DatePeriod initialization We need to free not only p here, but also b and e. --- ext/date/php_date.c | 6 ++++++ ext/date/tests/date_interval_bad_format_leak.phpt | 7 +++++++ 2 files changed, 13 insertions(+) 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) -- 2.40.0