Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
cares_wrap: use unref immediate to uv_close in destructor
  • Loading branch information
apapirovski committed Jan 23, 2018
commit c939d4e943986ee709a88a76effe6bc5a3a6221f
27 changes: 14 additions & 13 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class ChannelWrap : public AsyncWrap {

void Setup();
void EnsureServers();
void CleanupTimer();

void ModifyActivityQueryCount(int count);

Expand Down Expand Up @@ -503,7 +502,12 @@ void ChannelWrap::Setup() {

/* Initialize the timeout timer. The timer won't be started until the */
/* first socket is opened. */
CleanupTimer();
if (timer_handle_ != nullptr) {
auto close_cb = [](uv_handle_t* handle) {
delete reinterpret_cast<uv_timer_t*>(handle);
};
uv_close(reinterpret_cast<uv_handle_t*>(timer_handle_), close_cb);
}
timer_handle_ = new uv_timer_t();
timer_handle_->data = static_cast<void*>(this);
uv_timer_init(env()->event_loop(), timer_handle_);
Expand All @@ -517,20 +521,17 @@ ChannelWrap::~ChannelWrap() {
}

ares_destroy(channel_);
CleanupTimer();
}


void ChannelWrap::CleanupTimer() {
if (timer_handle_ == nullptr) return;

uv_close(reinterpret_cast<uv_handle_t*>(timer_handle_),
[](uv_handle_t* handle) {
delete reinterpret_cast<uv_timer_t*>(handle);
});
uv_timer_stop(timer_handle_);
auto close_cb = [](Environment* env, void* data) {
uv_close(reinterpret_cast<uv_handle_t*>(data), [](uv_handle_t* handle) {
delete reinterpret_cast<uv_timer_t*>(handle);
});
};
env()->SetUnrefImmediate(close_cb, timer_handle_);
timer_handle_ = nullptr;
}


void ChannelWrap::ModifyActivityQueryCount(int count) {
active_query_count_ += count;
if (active_query_count_ < 0) active_query_count_ = 0;
Expand Down