File tree 1 file changed +5
-0
lines changed
1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ using v8::Value;
70
70
71
71
namespace {
72
72
73
+ Mutex ares_library_mutex;
74
+
73
75
inline uint16_t cares_get_16bit (const unsigned char * p) {
74
76
return static_cast <uint32_t >(p[0 ] << 8U ) | (static_cast <uint32_t >(p[1 ]));
75
77
}
@@ -496,6 +498,7 @@ void ChannelWrap::Setup() {
496
498
497
499
int r;
498
500
if (!library_inited_) {
501
+ Mutex::ScopedLock lock (ares_library_mutex);
499
502
// Multiple calls to ares_library_init() increase a reference counter,
500
503
// so this is a no-op except for the first call to it.
501
504
r = ares_library_init (ARES_LIB_INIT_ALL);
@@ -509,6 +512,7 @@ void ChannelWrap::Setup() {
509
512
ARES_OPT_FLAGS | ARES_OPT_SOCK_STATE_CB);
510
513
511
514
if (r != ARES_SUCCESS) {
515
+ Mutex::ScopedLock lock (ares_library_mutex);
512
516
ares_library_cleanup ();
513
517
return env ()->ThrowError (ToErrorCodeString (r));
514
518
}
@@ -526,6 +530,7 @@ void ChannelWrap::Setup() {
526
530
527
531
ChannelWrap::~ChannelWrap () {
528
532
if (library_inited_) {
533
+ Mutex::ScopedLock lock (ares_library_mutex);
529
534
// This decreases the reference counter increased by ares_library_init().
530
535
ares_library_cleanup ();
531
536
}
You can’t perform that action at this time.
0 commit comments