iphlpapi: Don't allocate gobs of memory if the UDP table is empty.

This commit is contained in:
Juan Lang 2007-11-15 11:04:12 -08:00 committed by Alexandre Julliard
parent 72a59de299
commit 7e584b4340
2 changed files with 11 additions and 5 deletions

View File

@ -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;

View File

@ -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;