Skip to content

Commit 263f58f

Browse files
authored
Fix the destructor of AresResolver (#162)
1 parent 0923f6d commit 263f58f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

trantor/net/inner/AresResolver.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ AresResolver::AresResolver(EventLoop* loop, size_t timeout)
7373
{
7474
loop_ = getLoop();
7575
}
76+
loopValid_ = std::make_shared<bool>(true);
77+
loop_->runOnQuit([loopValid = loopValid_]() { *loopValid = false; });
7678
}
7779
void AresResolver::init()
7880
{
@@ -209,7 +211,7 @@ void AresResolver::onSockStateChange(int sockfd, bool read, bool write)
209211
// update
210212
// if (write) { } else { }
211213
}
212-
else
214+
else if (*loopValid_)
213215
{
214216
// remove
215217
it->second->disableAll();

trantor/net/inner/AresResolver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class AresResolver : public Resolver,
8686
void resolveInLoop(const std::string& hostname, const Callback& cb);
8787
void init();
8888
trantor::EventLoop* loop_;
89+
std::shared_ptr<bool> loopValid_;
8990
ares_channel ctx_{nullptr};
9091
bool timerActive_{false};
9192
using ChannelList = std::map<int, std::unique_ptr<trantor::Channel>>;

0 commit comments

Comments
 (0)