From e8b5ab9faeca4228200bbdb775805fcea5ae36fe Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sun, 14 Jun 2015 21:19:08 +0000 Subject: [PATCH] Fixed memory leak in LookupDNSAddr. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8451 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/pqinetwork.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libretroshare/src/pqi/pqinetwork.cc b/libretroshare/src/pqi/pqinetwork.cc index fc8ca62ce..00e24c600 100644 --- a/libretroshare/src/pqi/pqinetwork.cc +++ b/libretroshare/src/pqi/pqinetwork.cc @@ -846,20 +846,24 @@ bool LookupDNSAddr(std::string name, struct sockaddr_in &addr) #endif return false; } - - if ((res) && (res->ai_family == AF_INET)) + + if (res) { - addr = *((struct sockaddr_in *) res->ai_addr); - freeaddrinfo(res); + if (res->ai_family == AF_INET) + { + addr = *((struct sockaddr_in *) res->ai_addr); + freeaddrinfo(res); #ifdef NET_DEBUG - std::cerr << "LookupDNSAddr() getaddrinfo found address" << std::endl; - std::cerr << "addr: " << rs_inet_ntoa(addr.sin_addr) << std::endl; - std::cerr << "port: " << ntohs(addr.sin_port) << std::endl; + std::cerr << "LookupDNSAddr() getaddrinfo found address" << std::endl; + std::cerr << "addr: " << rs_inet_ntoa(addr.sin_addr) << std::endl; + std::cerr << "port: " << ntohs(addr.sin_port) << std::endl; #endif - return true; + return true; + } + freeaddrinfo(res); } - + #ifdef NET_DEBUG std::cerr << "getaddrinfo failed - no address" << std::endl; #endif