Skip to content

Commit

Permalink
src: use RAII cleanup in node_i18n.cc
Browse files Browse the repository at this point in the history
PR-URL: #23021
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
  • Loading branch information
addaleax authored and targos committed Sep 25, 2018
1 parent 87565c7 commit 2f659a3
Showing 1 changed file with 8 additions and 8 deletions.
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

0 comments on commit 2f659a3

Please sign in to comment.