Skip to content

Commit cba221a

Browse files
authored
Fix memory leak in NormalResolver (#163)
1 parent 263f58f commit cba221a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

trantor/net/inner/NormalResolver.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ void NormalResolver::resolve(const std::string &hostname,
6565
if (error == -1 || res == nullptr)
6666
{
6767
LOG_SYSERR << "InetAddress::resolve";
68+
if (res != nullptr)
69+
{
70+
freeaddrinfo(res);
71+
}
6872
callback(InetAddress{});
6973
return;
7074
}
@@ -83,6 +87,7 @@ void NormalResolver::resolve(const std::string &hostname,
8387
addr = *reinterpret_cast<struct sockaddr_in6 *>(res->ai_addr);
8488
inet = InetAddress(addr);
8589
}
90+
freeaddrinfo(res);
8691
callback(inet);
8792
{
8893
std::lock_guard<std::mutex> guard(thisPtr->globalMutex());

0 commit comments

Comments
 (0)