Skip to content

Commit

Permalink
ICU-22831 Fix memLeak in number_longnames.cpp by using LocalPointer
Browse files Browse the repository at this point in the history
Maybe fix issues in ICU-22800
  • Loading branch information
FrankYFTang committed Aug 6, 2024
1 parent 6c8c6aa commit 575bb78
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions icu4c/source/i18n/number_longnames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1481,17 +1481,16 @@ LongNameHandler* LongNameHandler::forCurrencyLongNames(const Locale &loc, const
const PluralRules *rules,
const MicroPropsGenerator *parent,
UErrorCode &status) {
auto* result = new LongNameHandler(rules, parent);
if (result == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
LocalPointer<LongNameHandler> result(new LongNameHandler(rules, parent), status);
if (U_FAILURE(status)) {
return nullptr;
}
UnicodeString simpleFormats[ARRAY_LENGTH];
getCurrencyLongNameData(loc, currency, simpleFormats, status);
if (U_FAILURE(status)) { return nullptr; }
result->simpleFormatsToModifiers(simpleFormats, {UFIELD_CATEGORY_NUMBER, UNUM_CURRENCY_FIELD}, status);
// TODO(icu-units#28): currency gender?
return result;
return result.orphan();
}

void LongNameHandler::simpleFormatsToModifiers(const UnicodeString *simpleFormats, Field field,
Expand Down

0 comments on commit 575bb78

Please sign in to comment.