iphlpapi: Don't allocate gobs of memory if the UDP table is empty.
This commit is contained in:
parent
72a59de299
commit
7e584b4340
|
@ -1665,8 +1665,10 @@ DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
|
|||
ret = ERROR_INVALID_PARAMETER;
|
||||
else {
|
||||
DWORD numEntries = getNumUdpEntries();
|
||||
DWORD size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
|
||||
DWORD size = sizeof(MIB_UDPTABLE);
|
||||
|
||||
if (numEntries > 1)
|
||||
size += (numEntries - 1) * sizeof(MIB_UDPROW);
|
||||
if (!pUdpTable || *pdwSize < size) {
|
||||
*pdwSize = size;
|
||||
ret = ERROR_INSUFFICIENT_BUFFER;
|
||||
|
@ -1676,8 +1678,9 @@ DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
|
|||
|
||||
ret = getUdpTable(&table, GetProcessHeap(), 0);
|
||||
if (!ret) {
|
||||
size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
|
||||
sizeof(MIB_UDPROW);
|
||||
size = sizeof(MIB_UDPTABLE);
|
||||
if (table->dwNumEntries > 1)
|
||||
size += (table->dwNumEntries - 1) * sizeof(MIB_UDPROW);
|
||||
if (*pdwSize < size) {
|
||||
*pdwSize = size;
|
||||
ret = ERROR_INSUFFICIENT_BUFFER;
|
||||
|
|
|
@ -1112,9 +1112,12 @@ DWORD getUdpTable(PMIB_UDPTABLE *ppUdpTable, HANDLE heap, DWORD flags)
|
|||
ret = ERROR_INVALID_PARAMETER;
|
||||
else {
|
||||
DWORD numEntries = getNumUdpEntries();
|
||||
PMIB_UDPTABLE table = HeapAlloc(heap, flags,
|
||||
sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW));
|
||||
DWORD size = sizeof(MIB_UDPTABLE);
|
||||
PMIB_UDPTABLE table;
|
||||
|
||||
if (numEntries > 1)
|
||||
size += (numEntries - 1) * sizeof(MIB_UDPROW);
|
||||
table = HeapAlloc(heap, flags, size);
|
||||
if (table) {
|
||||
FILE *fp;
|
||||
|
||||
|
|
Loading…
Reference in New Issue