os: fix GetInterfaceAddresses memory lieaky

PR-URL: https://github.com/nodejs/node/pull/58940
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
theanarkh 2025-07-06 01:33:23 +08:00 committed by GitHub
parent f5da8f89ee
commit b890c51ff2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -214,6 +214,9 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
return;
}
auto cleanup =
OnScopeLeave([&]() { uv_free_interface_addresses(interfaces, count); });
Local<Value> no_scope_id = Integer::New(isolate, -1);
LocalVector<Value> result(isolate);
result.reserve(count * 7);
@ -268,7 +271,6 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
}
}
uv_free_interface_addresses(interfaces, count);
args.GetReturnValue().Set(Array::New(isolate, result.data(), result.size()));
}