This repository was archived by the owner on Aug 31, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed
Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ using v8::Value;
7070
7171namespace {
7272
73+ Mutex ares_library_mutex;
74+
7375inline uint16_t cares_get_16bit (const unsigned char * p) {
7476 return static_cast <uint32_t >(p[0 ] << 8U ) | (static_cast <uint32_t >(p[1 ]));
7577}
@@ -496,6 +498,7 @@ void ChannelWrap::Setup() {
496498
497499 int r;
498500 if (!library_inited_) {
501+ Mutex::ScopedLock lock (ares_library_mutex);
499502 // Multiple calls to ares_library_init() increase a reference counter,
500503 // so this is a no-op except for the first call to it.
501504 r = ares_library_init (ARES_LIB_INIT_ALL);
@@ -509,6 +512,7 @@ void ChannelWrap::Setup() {
509512 ARES_OPT_FLAGS | ARES_OPT_SOCK_STATE_CB);
510513
511514 if (r != ARES_SUCCESS) {
515+ Mutex::ScopedLock lock (ares_library_mutex);
512516 ares_library_cleanup ();
513517 return env ()->ThrowError (ToErrorCodeString (r));
514518 }
@@ -526,6 +530,7 @@ void ChannelWrap::Setup() {
526530
527531ChannelWrap::~ChannelWrap () {
528532 if (library_inited_) {
533+ Mutex::ScopedLock lock (ares_library_mutex);
529534 // This decreases the reference counter increased by ares_library_init().
530535 ares_library_cleanup ();
531536 }
You can’t perform that action at this time.
0 commit comments