iphlpapi: Don't allocate gobs of memory if the IP address table is empty.
This commit is contained in:
parent
9ec6e33e32
commit
e1a836933f
@ -746,8 +746,11 @@ DWORD getIPAddrTable(PMIB_IPADDRTABLE *ppIpAddrTable, HANDLE heap, DWORD flags)
|
||||
ret = enumIPAddresses(&numAddresses, &ifc);
|
||||
if (!ret)
|
||||
{
|
||||
*ppIpAddrTable = HeapAlloc(heap, flags, sizeof(MIB_IPADDRTABLE) +
|
||||
(numAddresses - 1) * sizeof(MIB_IPADDRROW));
|
||||
DWORD size = sizeof(MIB_IPADDRTABLE);
|
||||
|
||||
if (numAddresses > 1)
|
||||
size += (numAddresses - 1) * sizeof(MIB_IPADDRROW);
|
||||
*ppIpAddrTable = HeapAlloc(heap, flags, size);
|
||||
if (*ppIpAddrTable) {
|
||||
DWORD i = 0, bcast;
|
||||
caddr_t ifPtr;
|
||||
|
@ -1172,17 +1172,17 @@ DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL
|
||||
ret = getIPAddrTable(&table, GetProcessHeap(), 0);
|
||||
if (ret == NO_ERROR)
|
||||
{
|
||||
ULONG size = sizeof(MIB_IPADDRTABLE) + (table->dwNumEntries - 1) *
|
||||
sizeof(MIB_IPADDRROW);
|
||||
ULONG size = sizeof(MIB_IPADDRTABLE);
|
||||
|
||||
if (table->dwNumEntries > 1)
|
||||
size += (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW);
|
||||
if (!pIpAddrTable || *pdwSize < size) {
|
||||
*pdwSize = size;
|
||||
ret = ERROR_INSUFFICIENT_BUFFER;
|
||||
}
|
||||
else {
|
||||
*pdwSize = size;
|
||||
memcpy(pIpAddrTable, table, sizeof(MIB_IPADDRTABLE) +
|
||||
(table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW));
|
||||
memcpy(pIpAddrTable, table, size);
|
||||
if (bOrder)
|
||||
qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
|
||||
sizeof(MIB_IPADDRROW), IpAddrTableSorter);
|
||||
|
Loading…
x
Reference in New Issue
Block a user