From b890c51ff29081c81a40d4910071cfdd80c40ff5 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Sun, 6 Jul 2025 01:33:23 +0800 Subject: [PATCH] os: fix GetInterfaceAddresses memory lieaky MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/58940 Reviewed-By: Juan José Arboleda Reviewed-By: Chengzhong Wu --- src/node_os.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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())); }