@@ -125,21 +125,27 @@ PHP_FUNCTION( msgfmt_format_message )
125125 efree (spattern );
126126 }
127127
128- if (INTL_DATA_ERROR_CODE ( mfo ) == U_PATTERN_SYNTAX_ERROR ) {
129- char * msg = NULL ;
130- smart_str parse_error_str ;
131- parse_error_str = intl_parse_error_to_string ( & parse_error );
132- spprintf ( & msg , 0 , "pattern syntax error (%s)" , parse_error_str .s ? ZSTR_VAL (parse_error_str .s ) : "unknown parser error" );
133- smart_str_free ( & parse_error_str );
134-
135- intl_error_set_code ( NULL , INTL_DATA_ERROR_CODE ( mfo ) );
136- intl_errors_set_custom_msg ( INTL_DATA_ERROR_P ( mfo ), msg , 1 );
137-
138- efree ( msg );
128+ /* Cannot use INTL_METHOD_CHECK_STATUS() as we need to free the message object formatter */
129+ if (U_FAILURE (INTL_DATA_ERROR_CODE (mfo ))) {
130+ if (INTL_DATA_ERROR_CODE ( mfo ) == U_PATTERN_SYNTAX_ERROR ) {
131+ char * msg = NULL ;
132+ smart_str parse_error_str ;
133+ parse_error_str = intl_parse_error_to_string ( & parse_error );
134+ spprintf ( & msg , 0 , "pattern syntax error (%s)" , parse_error_str .s ? ZSTR_VAL (parse_error_str .s ) : "unknown parser error" );
135+ smart_str_free ( & parse_error_str );
136+
137+ intl_error_set_code ( NULL , INTL_DATA_ERROR_CODE ( mfo ) );
138+ intl_errors_set_custom_msg ( INTL_DATA_ERROR_P ( mfo ), msg , 1 );
139+
140+ efree ( msg );
141+ } else {
142+ intl_errors_set_custom_msg ( INTL_DATA_ERROR_P (mfo ), "Creating message formatter failed" , 0 );
143+ }
144+ /* Reset custom error message as this is a static method that has no object */
145+ intl_errors_reset (INTL_DATA_ERROR_P (mfo ));
146+ umsg_close (MSG_FORMAT_OBJECT (mfo ));
139147 RETURN_FALSE ;
140- }
141-
142- INTL_METHOD_CHECK_STATUS (mfo , "Creating message formatter failed" );
148+ }
143149
144150 msgfmt_do_format (mfo , args , return_value );
145151
0 commit comments