From: Nikita Popov Date: Thu, 30 Jan 2020 10:13:04 +0000 (+0100) Subject: Fix leak in DatePeriod construction with invalid format X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=472fc3a2a9accc695aae1c3c10cb846396d64910;p=php Fix leak in DatePeriod construction with invalid format Same issue as I fixed in DateInterval construction before. --- diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 8b1bda20f0..2ac5a30d93 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -4266,6 +4266,9 @@ 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 (p) { + timelib_rel_time_dtor(p); + } } else { *st = b; *et = e; diff --git a/ext/date/tests/date_interval_bad_format_leak.phpt b/ext/date/tests/date_interval_bad_format_leak.phpt index 9d8af25ea4..d15bf57b3f 100644 --- a/ext/date/tests/date_interval_bad_format_leak.phpt +++ b/ext/date/tests/date_interval_bad_format_leak.phpt @@ -9,6 +9,13 @@ try { echo $e->getMessage(), "\n"; } +try { + $perid = new DatePeriod('P3"D'); +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} + ?> --EXPECT-- DateInterval::__construct(): Unknown or bad format (P3"D) +DatePeriod::__construct(): Unknown or bad format (P3"D)