Skip to content

Commit

Permalink
ICU-22830 Fix memLeak in numrange_fluent.cpp
Browse files Browse the repository at this point in the history
Maybe related to the leak in ICU-22800
  • Loading branch information
FrankYFTang committed Aug 5, 2024
1 parent 2f5a46f commit 1b6d37d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions icu4c/source/i18n/numrange_fluent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,8 @@ FormattedNumberRange LocalizedNumberRangeFormatter::formatFormattableRange(
return FormattedNumberRange(U_ILLEGAL_ARGUMENT_ERROR);
}

auto* results = new UFormattedNumberRangeData();
if (results == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
LocalPointer<UFormattedNumberRangeData> results(new UFormattedNumberRangeData(), status);
if (U_FAILURE(status)) {
return FormattedNumberRange(status);
}

Expand All @@ -333,9 +332,8 @@ FormattedNumberRange LocalizedNumberRangeFormatter::formatFormattableRange(

// Do not save the results object if we encountered a failure.
if (U_SUCCESS(status)) {
return FormattedNumberRange(results);
return FormattedNumberRange(results.orphan());
} else {
delete results;
return FormattedNumberRange(status);
}
}
Expand Down

0 comments on commit 1b6d37d

Please sign in to comment.