fix memroy leak in PinholeVerification()

see #459
This commit is contained in:
Thomas Bernard 2020-06-05 10:13:13 +02:00
parent f151cc1dd4
commit d5ba9c368e
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
1 changed files with 17 additions and 6 deletions

View File

@ -1538,23 +1538,34 @@ PinholeVerification(struct upnphttp * h, char * int_ip, unsigned short int_port)
if (inet_pton(AF_INET6, int_ip, &result_ip) <= 0)
{
n = getaddrinfo(int_ip, NULL, &hints, &ai);
if(!n && ai->ai_family == AF_INET6)
if (n == 0)
{
int found = 0;
for(p = ai; p; p = p->ai_next)
{
if(p->ai_family == AF_INET6)
{
inet_ntop(AF_INET6, (struct in6_addr *) p, int_ip, sizeof(struct in6_addr));
result_ip = *((struct in6_addr *) p);
found = 1;
/* TODO : deal with more than one ip per hostname */
break;
}
}
freeaddrinfo(ai);
if (!found)
{
syslog(LOG_ERR, "Failed to convert hostname '%s' to IPv6 address", int_ip);
SoapError(h, 402, "Invalid Args");
return -1;
}
}
else
{
syslog(LOG_ERR, "Failed to convert hostname '%s' to ip address", int_ip);
SoapError(h, 402, "Invalid Args");
return -1;
}
freeaddrinfo(p);
}
if(inet_ntop(AF_INET6, &(h->clientaddr_v6), senderAddr, INET6_ADDRSTRLEN) == NULL)