Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use RAII cleanup in node_i18n.cc #23021

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ class ConverterObject : public BaseObject, Converter {
result.AllocateSufficientStorage(limit);

UBool flush = (flags & CONVERTER_FLAGS_FLUSH) == CONVERTER_FLAGS_FLUSH;
OnScopeLeave cleanup([&]() {
if (flush) {
// Reset the converter state.
converter->bomSeen_ = false;
ucnv_reset(converter->conv);
}
});

const char* source = input_obj_data;
size_t source_length = input_obj_length;
Expand All @@ -238,17 +245,10 @@ class ConverterObject : public BaseObject, Converter {
result.SetLength(target - &result[0]);
ret = ToBufferEndian(env, &result);
args.GetReturnValue().Set(ret.ToLocalChecked());
goto reset;
return;
}

args.GetReturnValue().Set(status);

reset:
if (flush) {
// Reset the converter state
converter->bomSeen_ = false;
ucnv_reset(converter->conv);
}
}

void MemoryInfo(MemoryTracker* tracker) const override {
Expand Down