Merge pull request #2502 from PhenomRetroShare/Fix_rsGetHostByNameSpecDNS

Fix rsGetHostByNameSpecDNS by closing socket.
This commit is contained in:
csoler 2021-11-08 11:21:46 +01:00 committed by GitHub
commit 1d2b91a675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -193,6 +193,11 @@ bool rsGetHostByNameSpecDNS(const std::string& servername, const std::string& ho
RS_DBG("Sending Packet:\n", hexDump(buf, curSendSize));
#endif
int s = socket(serverAddr.ss_family , SOCK_DGRAM , IPPROTO_UDP); //UDP packet for DNS queries
if(s<0)
{
RS_ERR("Could not open socket.");
return false;
}
if (timeout_s > -1)
rs_setSockTimeout(s, true, timeout_s);
@ -205,6 +210,7 @@ bool rsGetHostByNameSpecDNS(const std::string& servername, const std::string& ho
if( send_size < 0)
{
RS_ERR("Send Failed with size = ", send_size);
close(s);
return false;
}
@ -221,6 +227,7 @@ bool rsGetHostByNameSpecDNS(const std::string& servername, const std::string& ho
, (struct sockaddr*)&serverAddr
, &sa_size
);
close(s); // No more need of this socket, close it.
if(rec_size <= 0)
{
RS_ERR("Receive Failed");