summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2017-02-15 01:19:36 +0100
committerlouiz’ <louiz@louiz.org>2017-02-15 01:19:36 +0100
commit561bbe9c145a80befc5b98c9865881e7f5d57648 (patch)
treee1305d2fb9cf8e9682778111f8ad9dbeecca77b8
parentfef585ad6699042e594f407afe78df1e40344efe (diff)
downloadbiboumi-561bbe9c145a80befc5b98c9865881e7f5d57648.tar.gz
biboumi-561bbe9c145a80befc5b98c9865881e7f5d57648.tar.bz2
biboumi-561bbe9c145a80befc5b98c9865881e7f5d57648.tar.xz
biboumi-561bbe9c145a80befc5b98c9865881e7f5d57648.zip
Fix a leak on getaddrinfo, thank you LeakSanitizer!
-rw-r--r--louloulibs/xmpp/jid.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/louloulibs/xmpp/jid.cpp b/louloulibs/xmpp/jid.cpp
index d17d4e9..493ddc1 100644
--- a/louloulibs/xmpp/jid.cpp
+++ b/louloulibs/xmpp/jid.cpp
@@ -71,10 +71,10 @@ std::string jidprep(const std::string& original)
hints.ai_flags = AI_NUMERICHOST;
hints.ai_family = AF_UNSPEC;
- struct addrinfo* res = nullptr;
- auto addrinfo_deleter = utils::make_scope_guard([res]() { if (res) freeaddrinfo(res); });
- if (::getaddrinfo(domain, nullptr, &hints, &res) || !res ||
- (res->ai_family != AF_INET && res->ai_family != AF_INET6))
+ struct addrinfo* addr_res = nullptr;
+ const auto ret = ::getaddrinfo(domain, nullptr, &hints, &addr_res);
+ auto addrinfo_deleter = utils::make_scope_guard([addr_res] { freeaddrinfo(addr_res); });
+ if (ret || !addr_res || (addr_res->ai_family != AF_INET && addr_res->ai_family != AF_INET6))
{ // Not an IP, run nameprep on it
rc = static_cast<Stringprep_rc>(::stringprep(domain, max_jid_part_len,
static_cast<Stringprep_profile_flags>(0), stringprep_nameprep));
@@ -114,7 +114,7 @@ std::string jidprep(const std::string& original)
else
*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:
// the longest possible IPv6 is way shorter than max_jid_part_len
::memmove(domain + 1, domain, jid.domain.size());