1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 09:29:52 +03:00

Mayaqua/DNS.c: Fix memory leaks

52 bytes in 2 blocks are definitely lost in loss record 5 of 13
   at 0x483877F: malloc (vg_replace_malloc.c:307)
   by 0x4ABB1BB: UnixMemoryAlloc (Unix.c:2033)
   by 0x4A7FABF: InternalMalloc (Memory.c:3819)
   by 0x4A7B769: MallocEx (Memory.c:3650)
   by 0x4A7B769: Malloc (Memory.c:3641)
   by 0x4AA71A9: CopyStr (Str.c:1884)
   by 0x4A61A9C: DnsCacheReverseUpdate (DNS.c:257)
   by 0x4A62123: DnsResolveReverse (DNS.c:506)
   by 0x4A93EB3: GetHostName (Network.c:15023)
   by 0x4A93EB3: AcceptInitEx (Network.c:12589)
   by 0x4934659: TCPAcceptedThread (Listener.c:172)
   by 0x4A76469: ThreadPoolProc (Kernel.c:872)
   by 0x4ABD159: UnixDefaultThreadProc (Unix.c:1589)
   by 0x51C2EA6: start_thread (pthread_create.c:477)

2,280 (684 direct, 1,596 indirect) bytes in 9 blocks are definitely lost in loss record 11 of 13
   at 0x483877F: malloc (vg_replace_malloc.c:307)
   by 0x4C65AC5: gaih_inet.constprop.0 (getaddrinfo.c:1058)
   by 0x4C67224: getaddrinfo (getaddrinfo.c:2256)
   by 0x4A61E06: DnsResolver (DNS.c:404)
   by 0x4A76469: ThreadPoolProc (Kernel.c:872)
   by 0x4ABD159: UnixDefaultThreadProc (Unix.c:1589)
   by 0x51C2EA6: start_thread (pthread_create.c:477)
   by 0x4C7CDEE: clone (clone.S:95)
This commit is contained in:
Davide Beatrici 2021-04-21 22:34:10 +02:00
parent 76395d8f8d
commit 3a595b4a46

View File

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