From 83213b0c46f964c78eee2dd04ce9eb1e22547c80 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 27 Jul 2025 12:20:21 +0100 Subject: [PATCH] Fixed GH-19261: msgfmt_parse_message leaks on message format failure. close GH-19262 --- ext/intl/msgformat/msgformat_parse.c | 3 ++- ext/intl/tests/gh19261.phpt | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ext/intl/tests/gh19261.phpt diff --git a/ext/intl/msgformat/msgformat_parse.c b/ext/intl/msgformat/msgformat_parse.c index baa6dfcce74b0..31441c92373da 100644 --- a/ext/intl/msgformat/msgformat_parse.c +++ b/ext/intl/msgformat/msgformat_parse.c @@ -127,10 +127,11 @@ PHP_FUNCTION( msgfmt_parse_message ) if(spattern && spattern_len) { efree(spattern); } - INTL_METHOD_CHECK_STATUS(mfo, "Creating message formatter failed"); + INTL_METHOD_CHECK_STATUS_OR_GOTO(mfo, "Creating message formatter failed", clean); msgfmt_do_parse(mfo, source, src_len, return_value); +clean: /* drop the temporary formatter */ msgformat_data_free(&mfo->mf_data); } diff --git a/ext/intl/tests/gh19261.phpt b/ext/intl/tests/gh19261.phpt new file mode 100644 index 0000000000000..3f281919a9562 --- /dev/null +++ b/ext/intl/tests/gh19261.phpt @@ -0,0 +1,28 @@ +--TEST-- +MessageFormatter::parseMessage() with invalid locale +--EXTENSIONS-- +intl +--CREDITS-- +girgias@php.net +--FILE-- + +--EXPECT-- +bool(false) +string(59) "Creating message formatter failed: U_ILLEGAL_ARGUMENT_ERROR" +bool(false) +string(59) "Creating message formatter failed: U_ILLEGAL_ARGUMENT_ERROR"