1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 17:39:53 +03:00

Merge pull request #1335 from davidebeatrici/mayaqua-dns-memory-leaks-fix

Mayaqua/DNS.c: Fix memory leaks
This commit is contained in:
Ilya Shipitsin 2021-04-22 08:57:50 +05:00 committed by GitHub
commit 19af52e288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -79,7 +79,7 @@ void DnsFree()
{ {
for (UINT i = 0; i < LIST_NUM(cache_reverse); ++i) for (UINT i = 0; i < LIST_NUM(cache_reverse); ++i)
{ {
DNS_CACHE_REVERSE *entry = LIST_DATA(cache, i); DNS_CACHE_REVERSE *entry = LIST_DATA(cache_reverse, i);
Free(entry->Hostname); Free(entry->Hostname);
Free(entry); Free(entry);
} }
@ -234,7 +234,7 @@ DNS_CACHE_REVERSE *DnsCacheReverseUpdate(const IP *ip, const char *hostname)
{ {
if (entry != NULL) if (entry != NULL)
{ {
Delete(cache, entry); Delete(cache_reverse, entry);
Free(entry); Free(entry);
entry = NULL; entry = NULL;
} }
@ -246,7 +246,7 @@ DNS_CACHE_REVERSE *DnsCacheReverseUpdate(const IP *ip, const char *hostname)
entry = ZeroMalloc(sizeof(DNS_CACHE_REVERSE)); entry = ZeroMalloc(sizeof(DNS_CACHE_REVERSE));
Copy(&entry->IP, ip, sizeof(entry->IP)); Copy(&entry->IP, ip, sizeof(entry->IP));
Add(cache, entry); Add(cache_reverse, entry);
} }
entry->Expiration = Tick64(); entry->Expiration = Tick64();
@ -400,13 +400,13 @@ void DnsResolver(THREAD *t, void *param)
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
hints.ai_flags = AI_ALL | AI_ADDRCONFIG | AI_V4MAPPED; hints.ai_flags = AI_ALL | AI_ADDRCONFIG | AI_V4MAPPED;
struct addrinfo *result; struct addrinfo *results;
const int ret = getaddrinfo(resolver->Hostname, NULL, &hints, &result); const int ret = getaddrinfo(resolver->Hostname, NULL, &hints, &results);
if (ret == 0) if (ret == 0)
{ {
bool ipv6_ok = false; bool ipv6_ok = false;
bool ipv4_ok = false; bool ipv4_ok = false;
do for (struct addrinfo *result = results; result != NULL; result = result->ai_next)
{ {
IP ip; IP ip;
const struct sockaddr_in6 *in = (struct sockaddr_in6 *)result->ai_addr; const struct sockaddr_in6 *in = (struct sockaddr_in6 *)result->ai_addr;
@ -422,11 +422,11 @@ void DnsResolver(THREAD *t, void *param)
Copy(&resolver->IPv4, &ip, sizeof(resolver->IPv4)); Copy(&resolver->IPv4, &ip, sizeof(resolver->IPv4));
ipv4_ok = true; ipv4_ok = true;
} }
}
result = result->ai_next;
} while (result != NULL && (ipv6_ok == false || ipv4_ok == false));
resolver->OK = true; resolver->OK = true;
freeaddrinfo(results);
} }
else if (ret != EAI_NONAME) else if (ret != EAI_NONAME)
{ {