From d7d22ead2b2fd28208475e87e7dd8ed9859e1ac5 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 10 Aug 2017 16:56:04 +0200 Subject: [PATCH] src: add comments for cares library init refcount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref: https://github.com/nodejs/node/pull/14738 PR-URL: https://github.com/nodejs/node/pull/14743 Reviewed-By: Timothy Gu Reviewed-By: Ben Noordhuis Reviewed-By: Tobias Nießen Reviewed-By: Khaidi Chu Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/cares_wrap.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 53a005444cc498..7869651a456c0a 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -489,6 +489,8 @@ void ChannelWrap::Setup() { int r; if (!library_inited_) { + // Multiple calls to ares_library_init() increase a reference counter, + // so this is a no-op except for the first call to it. r = ares_library_init(ARES_LIB_INIT_ALL); if (r != ARES_SUCCESS) return env()->ThrowError(ToErrorCodeString(r)); @@ -516,8 +518,10 @@ void ChannelWrap::Setup() { ChannelWrap::~ChannelWrap() { - if (library_inited_) + if (library_inited_) { + // This decreases the reference counter increased by ares_library_init(). ares_library_cleanup(); + } ares_destroy(channel_); CleanupTimer();