Skip to content

Commit

Permalink
Fix leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Oct 2, 2024
1 parent 04b9cf2 commit c048313
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
8 changes: 3 additions & 5 deletions icu4c/source/i18n/messageformat2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ FunctionOptions MessageFormatter::resolveOptions(const Environment& env, const O
}
return InternalValue(defaultFormatterName,
FunctionOptions(),
std::move(operand),
status);
std::move(operand));
} else {
randVal = eval(context, std::move(randVal), status);
// Don't call the function on error values
Expand All @@ -320,8 +319,7 @@ FunctionOptions MessageFormatter::resolveOptions(const Environment& env, const O
// Call the formatter function
return InternalValue(functionName,
std::move(resolvedOptions),
std::move(operand),
status);
std::move(operand));
}
}

Expand Down Expand Up @@ -441,7 +439,7 @@ void MessageFormatter::matchSelectorKeys(const UVector& keys,
// Return an empty list of matches
return;
}
auto selectorImpl = getSelector(context, selectorName, status);
LocalPointer<Selector> selectorImpl(getSelector(context, selectorName, status));
if (U_FAILURE(status)) {
return;
}
Expand Down
17 changes: 6 additions & 11 deletions icu4c/source/i18n/messageformat2_evaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,10 @@ InternalValue::InternalValue(InternalValue&& other) {
}

InternalValue::InternalValue(const FunctionName& name,
FunctionOptions&& options,
FormattedPlaceholder&& rand,
UErrorCode& status) : fallbackString(""), functionName(name) {
if (U_FAILURE(status)) {
return;
}
resolvedOptions.adoptInstead(create<FunctionOptions>(std::move(options), status));
operand = std::move(rand);
}
FunctionOptions&& options,
FormattedPlaceholder&& rand)
: fallbackString(""), functionName(name),
resolvedOptions(std::move(options)), operand(std::move(rand)) {}

FormattedPlaceholder InternalValue::takeValue(UErrorCode& status) {
if (U_FAILURE(status)) {
Expand Down Expand Up @@ -164,11 +159,11 @@ FunctionOptions InternalValue::takeOptions(UErrorCode& status) {
if (U_FAILURE(status)) {
return {};
}
if (!resolvedOptions.isValid()) {
if (!isSuspension()) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return {};
}
return std::move(*resolvedOptions.orphan());
return std::move(resolvedOptions);
}
// Only works if not fully evaluated
FunctionName InternalValue::getFunctionName(UErrorCode& status) const {
Expand Down
8 changes: 3 additions & 5 deletions icu4c/source/i18n/messageformat2_evaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ namespace message2 {
explicit InternalValue(UnicodeString fb) : fallbackString(fb) {}
// Fully-evaluated value constructor
explicit InternalValue(FormattedPlaceholder&& f)
: fallbackString(""), functionName(""), resolvedOptions(nullptr),
operand(std::move(f)) {}
: fallbackString(""), functionName(""), operand(std::move(f)) {}
// Suspension constructor
InternalValue(const FunctionName& name,
FunctionOptions&& options,
FormattedPlaceholder&& rand,
UErrorCode& status);
FormattedPlaceholder&& rand);
// Error code is set if this isn't fully evaluated
FormattedPlaceholder takeValue(UErrorCode& status);
// Error code is set if this is not a suspension
Expand All @@ -81,7 +79,7 @@ namespace message2 {
private:
UnicodeString fallbackString; // Non-empty if fallback
FunctionName functionName; // Non-empty if this is a suspension
LocalPointer<FunctionOptions> resolvedOptions; // Valid iff this is a suspension
FunctionOptions resolvedOptions; // Ignored unless this is a suspension
FormattedPlaceholder operand;
}; // class InternalValue

Expand Down

0 comments on commit c048313

Please sign in to comment.