Skip to content

Commit d7d22ea

Browse files
committed
src: add comments for cares library init refcount
Ref: #14738 PR-URL: #14743 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b87fae9 commit d7d22ea

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/cares_wrap.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ void ChannelWrap::Setup() {
489489

490490
int r;
491491
if (!library_inited_) {
492+
// Multiple calls to ares_library_init() increase a reference counter,
493+
// so this is a no-op except for the first call to it.
492494
r = ares_library_init(ARES_LIB_INIT_ALL);
493495
if (r != ARES_SUCCESS)
494496
return env()->ThrowError(ToErrorCodeString(r));
@@ -516,8 +518,10 @@ void ChannelWrap::Setup() {
516518

517519

518520
ChannelWrap::~ChannelWrap() {
519-
if (library_inited_)
521+
if (library_inited_) {
522+
// This decreases the reference counter increased by ares_library_init().
520523
ares_library_cleanup();
524+
}
521525

522526
ares_destroy(channel_);
523527
CleanupTimer();

0 commit comments

Comments
 (0)