diff --git a/src/node_os.cc b/src/node_os.cc index 3fa8584787..f2b449ac0d 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -214,6 +214,9 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo& args) { return; } + auto cleanup = + OnScopeLeave([&]() { uv_free_interface_addresses(interfaces, count); }); + Local no_scope_id = Integer::New(isolate, -1); LocalVector result(isolate); result.reserve(count * 7); @@ -268,7 +271,6 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo& args) { } } - uv_free_interface_addresses(interfaces, count); args.GetReturnValue().Set(Array::New(isolate, result.data(), result.size())); }