-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
src: use smart pointers in cares_wrap.cc #23813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4f84dde
src: use smart pointers in cares_wrap.cc
danbev c6b4ed9
squash: fix err checks
danbev a6ee1d3
squash: use std::make_unique where applicable
danbev bb9f5c7
squash: wrap release in USE macro
danbev a0c36a5
squash: add missing USE wrapping
danbev 25c405e
squash: add comment about release()
danbev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1797,22 +1797,24 @@ static void Query(const FunctionCallbackInfo<Value>& args) { | |
|
|
||
| Local<Object> req_wrap_obj = args[0].As<Object>(); | ||
| Local<String> string = args[1].As<String>(); | ||
| Wrap* wrap = new Wrap(channel, req_wrap_obj); | ||
| std::unique_ptr<Wrap> wrap {new Wrap(channel, req_wrap_obj)}; | ||
|
|
||
| node::Utf8Value name(env->isolate(), string); | ||
| channel->ModifyActivityQueryCount(1); | ||
| int err = wrap->Send(*name); | ||
| if (err) { | ||
| channel->ModifyActivityQueryCount(-1); | ||
| delete wrap; | ||
| } else { | ||
| wrap.release(); | ||
danbev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| args.GetReturnValue().Set(err); | ||
| } | ||
|
|
||
|
|
||
| void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { | ||
| GetAddrInfoReqWrap* req_wrap = static_cast<GetAddrInfoReqWrap*>(req->data); | ||
| std::unique_ptr<GetAddrInfoReqWrap> req_wrap { | ||
refack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| static_cast<GetAddrInfoReqWrap*>(req->data)}; | ||
| Environment* env = req_wrap->env(); | ||
|
|
||
| HandleScope handle_scope(env->isolate()); | ||
|
|
@@ -1869,21 +1871,20 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { | |
| uv_freeaddrinfo(res); | ||
danbev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| TRACE_EVENT_NESTABLE_ASYNC_END2( | ||
| TRACING_CATEGORY_NODE2(dns, native), "lookup", req_wrap, | ||
| TRACING_CATEGORY_NODE2(dns, native), "lookup", req_wrap.get(), | ||
| "count", n, "verbatim", verbatim); | ||
|
|
||
| // Make the callback into JavaScript | ||
| req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); | ||
|
|
||
| delete req_wrap; | ||
| } | ||
|
|
||
|
|
||
| void AfterGetNameInfo(uv_getnameinfo_t* req, | ||
| int status, | ||
| const char* hostname, | ||
| const char* service) { | ||
| GetNameInfoReqWrap* req_wrap = static_cast<GetNameInfoReqWrap*>(req->data); | ||
| std::unique_ptr<GetNameInfoReqWrap> req_wrap { | ||
| static_cast<GetNameInfoReqWrap*>(req->data)}; | ||
| Environment* env = req_wrap->env(); | ||
|
|
||
| HandleScope handle_scope(env->isolate()); | ||
|
|
@@ -1904,14 +1905,12 @@ void AfterGetNameInfo(uv_getnameinfo_t* req, | |
| } | ||
|
|
||
| TRACE_EVENT_NESTABLE_ASYNC_END2( | ||
| TRACING_CATEGORY_NODE2(dns, native), "lookupService", req_wrap, | ||
| TRACING_CATEGORY_NODE2(dns, native), "lookupService", req_wrap.get(), | ||
| "hostname", TRACE_STR_COPY(hostname), | ||
| "service", TRACE_STR_COPY(service)); | ||
|
|
||
| // Make the callback into JavaScript | ||
| req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); | ||
|
|
||
| delete req_wrap; | ||
| } | ||
|
|
||
| using ParseIPResult = decltype(static_cast<ares_addr_port_node*>(0)->addr); | ||
|
|
@@ -1971,7 +1970,8 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) { | |
| CHECK(0 && "bad address family"); | ||
| } | ||
|
|
||
| auto req_wrap = new GetAddrInfoReqWrap(env, req_wrap_obj, args[4]->IsTrue()); | ||
| std::unique_ptr<GetAddrInfoReqWrap> req_wrap { | ||
danbev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new GetAddrInfoReqWrap(env, req_wrap_obj, args[4]->IsTrue())}; | ||
|
|
||
| struct addrinfo hints; | ||
| memset(&hints, 0, sizeof(struct addrinfo)); | ||
|
|
@@ -1980,7 +1980,7 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) { | |
| hints.ai_flags = flags; | ||
|
|
||
| TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( | ||
| TRACING_CATEGORY_NODE2(dns, native), "lookup", req_wrap, | ||
| TRACING_CATEGORY_NODE2(dns, native), "lookup", req_wrap.get(), | ||
| "hostname", TRACE_STR_COPY(*hostname), | ||
| "family", | ||
| family == AF_INET ? "ipv4" : family == AF_INET6 ? "ipv6" : "unspec"); | ||
|
|
@@ -1990,8 +1990,8 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) { | |
| *hostname, | ||
| nullptr, | ||
| &hints); | ||
| if (err) | ||
| delete req_wrap; | ||
| if (!err) | ||
|
||
| req_wrap.release(); | ||
danbev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| args.GetReturnValue().Set(err); | ||
| } | ||
|
|
@@ -2011,18 +2011,19 @@ void GetNameInfo(const FunctionCallbackInfo<Value>& args) { | |
| CHECK(uv_ip4_addr(*ip, port, reinterpret_cast<sockaddr_in*>(&addr)) == 0 || | ||
| uv_ip6_addr(*ip, port, reinterpret_cast<sockaddr_in6*>(&addr)) == 0); | ||
|
|
||
| GetNameInfoReqWrap* req_wrap = new GetNameInfoReqWrap(env, req_wrap_obj); | ||
| std::unique_ptr<GetNameInfoReqWrap> req_wrap { | ||
| new GetNameInfoReqWrap(env, req_wrap_obj)}; | ||
|
|
||
| TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( | ||
| TRACING_CATEGORY_NODE2(dns, native), "lookupService", req_wrap, | ||
| TRACING_CATEGORY_NODE2(dns, native), "lookupService", req_wrap.get(), | ||
| "ip", TRACE_STR_COPY(*ip), "port", port); | ||
|
|
||
| int err = req_wrap->Dispatch(uv_getnameinfo, | ||
| AfterGetNameInfo, | ||
| reinterpret_cast<struct sockaddr*>(&addr), | ||
| NI_NAMEREQD); | ||
| if (err) | ||
| delete req_wrap; | ||
| if (!err) | ||
| req_wrap.release(); | ||
danbev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| args.GetReturnValue().Set(err); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.