@@ -26,6 +26,8 @@ extern "C" {
2626#include " listformatter_class.h"
2727#include " listformatter_arginfo.h"
2828
29+ #include < memory>
30+
2931static zend_object_handlers listformatter_handlers;
3032
3133static void listformatter_free_obj (zend_object *object)
@@ -134,7 +136,7 @@ PHP_METHOD(IntlListFormatter, format)
134136 RETURN_EMPTY_STRING ();
135137 }
136138
137- UnicodeString * items = new UnicodeString[count];
139+ std::unique_ptr< UnicodeString[]> items ( new UnicodeString[count]) ;
138140 uint32_t i = 0 ;
139141 zval *val;
140142
@@ -144,14 +146,12 @@ PHP_METHOD(IntlListFormatter, format)
144146
145147 str_val = zval_try_get_tmp_string (val, &tmp_str);
146148 if (UNEXPECTED (!str_val)) {
147- delete[] items;
148149 RETURN_THROWS ();
149150 }
150151 intl_stringFromChar (items[i], ZSTR_VAL (str_val), ZSTR_LEN (str_val), &conv_status);
151152 zend_tmp_string_release (tmp_str);
152153
153154 if (U_FAILURE (conv_status)) {
154- delete[] items;
155155 intl_error_set (nullptr , conv_status, " Failed to convert string to UTF-16" );
156156 RETURN_FALSE;
157157 }
@@ -162,8 +162,7 @@ PHP_METHOD(IntlListFormatter, format)
162162 UErrorCode status = U_ZERO_ERROR;
163163 UnicodeString result;
164164
165- LISTFORMATTER_OBJECT (obj)->format (items, count, result, status);
166- delete[] items;
165+ LISTFORMATTER_OBJECT (obj)->format (items.get (), count, result, status);
167166
168167 if (U_FAILURE (status)) {
169168 intl_error_set (nullptr , status, " Failed to format list" );
0 commit comments