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);
|
ret = enumIPAddresses(&numAddresses, &ifc);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
*ppIpAddrTable = HeapAlloc(heap, flags, sizeof(MIB_IPADDRTABLE) +
|
DWORD size = sizeof(MIB_IPADDRTABLE);
|
||||||
(numAddresses - 1) * sizeof(MIB_IPADDRROW));
|
|
||||||
|
if (numAddresses > 1)
|
||||||
|
size += (numAddresses - 1) * sizeof(MIB_IPADDRROW);
|
||||||
|
*ppIpAddrTable = HeapAlloc(heap, flags, size);
|
||||||
if (*ppIpAddrTable) {
|
if (*ppIpAddrTable) {
|
||||||
DWORD i = 0, bcast;
|
DWORD i = 0, bcast;
|
||||||
caddr_t ifPtr;
|
caddr_t ifPtr;
|
||||||
|
@ -1172,17 +1172,17 @@ DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL
|
|||||||
ret = getIPAddrTable(&table, GetProcessHeap(), 0);
|
ret = getIPAddrTable(&table, GetProcessHeap(), 0);
|
||||||
if (ret == NO_ERROR)
|
if (ret == NO_ERROR)
|
||||||
{
|
{
|
||||||
ULONG size = sizeof(MIB_IPADDRTABLE) + (table->dwNumEntries - 1) *
|
ULONG size = sizeof(MIB_IPADDRTABLE);
|
||||||
sizeof(MIB_IPADDRROW);
|
|
||||||
|
|
||||||
|
if (table->dwNumEntries > 1)
|
||||||
|
size += (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW);
|
||||||
if (!pIpAddrTable || *pdwSize < size) {
|
if (!pIpAddrTable || *pdwSize < size) {
|
||||||
*pdwSize = size;
|
*pdwSize = size;
|
||||||
ret = ERROR_INSUFFICIENT_BUFFER;
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*pdwSize = size;
|
*pdwSize = size;
|
||||||
memcpy(pIpAddrTable, table, sizeof(MIB_IPADDRTABLE) +
|
memcpy(pIpAddrTable, table, size);
|
||||||
(table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW));
|
|
||||||
if (bOrder)
|
if (bOrder)
|
||||||
qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
|
qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
|
||||||
sizeof(MIB_IPADDRROW), IpAddrTableSorter);
|
sizeof(MIB_IPADDRROW), IpAddrTableSorter);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user