Fix a leak on getaddrinfo, thank you LeakSanitizer!
This commit is contained in:
@@ -71,10 +71,10 @@ std::string jidprep(const std::string& original)
|
|||||||
hints.ai_flags = AI_NUMERICHOST;
|
hints.ai_flags = AI_NUMERICHOST;
|
||||||
hints.ai_family = AF_UNSPEC;
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
|
||||||
struct addrinfo* res = nullptr;
|
struct addrinfo* addr_res = nullptr;
|
||||||
auto addrinfo_deleter = utils::make_scope_guard([res]() { if (res) freeaddrinfo(res); });
|
const auto ret = ::getaddrinfo(domain, nullptr, &hints, &addr_res);
|
||||||
if (::getaddrinfo(domain, nullptr, &hints, &res) || !res ||
|
auto addrinfo_deleter = utils::make_scope_guard([addr_res] { freeaddrinfo(addr_res); });
|
||||||
(res->ai_family != AF_INET && res->ai_family != AF_INET6))
|
if (ret || !addr_res || (addr_res->ai_family != AF_INET && addr_res->ai_family != AF_INET6))
|
||||||
{ // Not an IP, run nameprep on it
|
{ // Not an IP, run nameprep on it
|
||||||
rc = static_cast<Stringprep_rc>(::stringprep(domain, max_jid_part_len,
|
rc = static_cast<Stringprep_rc>(::stringprep(domain, max_jid_part_len,
|
||||||
static_cast<Stringprep_profile_flags>(0), stringprep_nameprep));
|
static_cast<Stringprep_profile_flags>(0), stringprep_nameprep));
|
||||||
@@ -114,7 +114,7 @@ std::string jidprep(const std::string& original)
|
|||||||
else
|
else
|
||||||
*domain_end = '\0';
|
*domain_end = '\0';
|
||||||
}
|
}
|
||||||
else if (res->ai_family == AF_INET6)
|
else if (addr_res->ai_family == AF_INET6)
|
||||||
{ // IPv6, surround it with []. The length is always enough:
|
{ // IPv6, surround it with []. The length is always enough:
|
||||||
// the longest possible IPv6 is way shorter than max_jid_part_len
|
// the longest possible IPv6 is way shorter than max_jid_part_len
|
||||||
::memmove(domain + 1, domain, jid.domain.size());
|
::memmove(domain + 1, domain, jid.domain.size());
|
||||||
|
|||||||
Reference in New Issue
Block a user