From 8e3b400da230606e2da57b198e75ae88d1bb3d8e Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 22 Sep 2018 15:15:05 +0200 Subject: [PATCH] src: use RAII cleanup in node_i18n.cc --- src/node_i18n.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/node_i18n.cc b/src/node_i18n.cc index abe8addfadccde..e87f8f59550e19 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -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; @@ -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 {