From 7c75539a88b39e3a860d8e27ae96fdeb4590b449 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Sun, 24 Jul 2022 13:04:54 +0800 Subject: [PATCH] dns: fix cares memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/43912 Refs: https://github.com/nodejs/node/pull/39735 Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: Tobias Nießen Reviewed-By: Darshan Sen --- src/cares_wrap.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 30e27ecf70a837..a16a0dcbd1bcec 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -1428,6 +1428,7 @@ static void Query(const FunctionCallbackInfo& args) { void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { + auto cleanup = OnScopeLeave([&]() { uv_freeaddrinfo(res); }); std::unique_ptr req_wrap { static_cast(req->data)}; Environment* env = req_wrap->env(); @@ -1488,8 +1489,6 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { argv[1] = results; } - uv_freeaddrinfo(res); - TRACE_EVENT_NESTABLE_ASYNC_END2( TRACING_CATEGORY_NODE2(dns, native), "lookup", req_wrap.get(), "count", n, "verbatim", verbatim);