mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 14:37:41 +00:00
Get rid of most _alloca use and remove ALLOCA().
This commit is contained in:
@ -90,41 +90,40 @@ static unsigned s_nextLookupCancelId = 1;
|
||||
static void LookupProcess (Lookup * lookup, unsigned error) {
|
||||
unsigned count = 0;
|
||||
NetAddress * addrs = nil;
|
||||
for (ONCE) {
|
||||
if (error)
|
||||
break;
|
||||
|
||||
const HOSTENT & host = * (HOSTENT *) lookup->buffer;
|
||||
if (host.h_addrtype != AF_INET)
|
||||
break;
|
||||
if (host.h_length != sizeof(in_addr))
|
||||
break;
|
||||
if (!host.h_addr_list)
|
||||
break;
|
||||
if (error)
|
||||
return;
|
||||
|
||||
in_addr const * const * const inAddr = (in_addr **) host.h_addr_list;
|
||||
const HOSTENT & host = * (HOSTENT *) lookup->buffer;
|
||||
if (host.h_addrtype != AF_INET)
|
||||
return;
|
||||
if (host.h_length != sizeof(in_addr))
|
||||
return;
|
||||
if (!host.h_addr_list)
|
||||
return;
|
||||
|
||||
// count the number of addresses
|
||||
while (inAddr[count])
|
||||
++count;
|
||||
in_addr const * const * const inAddr = (in_addr **) host.h_addr_list;
|
||||
|
||||
// allocate a buffer large enough to hold all the addresses
|
||||
addrs = (NetAddress *) _alloca(sizeof(*addrs) * count);
|
||||
MemZero(addrs, sizeof(*addrs) * count);
|
||||
// count the number of addresses
|
||||
while (inAddr[count])
|
||||
++count;
|
||||
|
||||
// fill in address data
|
||||
const uint16_t port = htons((uint16_t) lookup->port);
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
sockaddr_in * inetaddr = (sockaddr_in *) &addrs[i];
|
||||
inetaddr->sin_family = AF_INET;
|
||||
inetaddr->sin_addr = *inAddr[i];
|
||||
inetaddr->sin_port = port;
|
||||
}
|
||||
// allocate a buffer large enough to hold all the addresses
|
||||
addrs = (NetAddress *)malloc(sizeof(*addrs) * count);
|
||||
MemZero(addrs, sizeof(*addrs) * count);
|
||||
|
||||
if (host.h_name && host.h_name[0])
|
||||
StrToUnicode(lookup->name, host.h_name, arrsize(lookup->name));
|
||||
// fill in address data
|
||||
const uint16_t port = htons((uint16_t) lookup->port);
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
sockaddr_in * inetaddr = (sockaddr_in *) &addrs[i];
|
||||
inetaddr->sin_family = AF_INET;
|
||||
inetaddr->sin_addr = *inAddr[i];
|
||||
inetaddr->sin_port = port;
|
||||
}
|
||||
|
||||
if (host.h_name && host.h_name[0])
|
||||
StrToUnicode(lookup->name, host.h_name, arrsize(lookup->name));
|
||||
|
||||
if (lookup->lookupProc)
|
||||
lookup->lookupProc(lookup->param, lookup->name, count, addrs);
|
||||
|
||||
@ -134,6 +133,8 @@ static void LookupProcess (Lookup * lookup, unsigned error) {
|
||||
ASSERT(!lookup->link.IsLinked());
|
||||
delete lookup;
|
||||
PerfSubCounter(kAsyncPerfNameLookupAttemptsCurr, 1);
|
||||
|
||||
free(addrs);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
Reference in New Issue
Block a user