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;
|
ret = ERROR_INVALID_PARAMETER;
|
||||||
else {
|
else {
|
||||||
DWORD numEntries = getNumUdpEntries();
|
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) {
|
if (!pUdpTable || *pdwSize < size) {
|
||||||
*pdwSize = size;
|
*pdwSize = size;
|
||||||
ret = ERROR_INSUFFICIENT_BUFFER;
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
||||||
|
@ -1676,8 +1678,9 @@ DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
|
||||||
|
|
||||||
ret = getUdpTable(&table, GetProcessHeap(), 0);
|
ret = getUdpTable(&table, GetProcessHeap(), 0);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
|
size = sizeof(MIB_UDPTABLE);
|
||||||
sizeof(MIB_UDPROW);
|
if (table->dwNumEntries > 1)
|
||||||
|
size += (table->dwNumEntries - 1) * sizeof(MIB_UDPROW);
|
||||||
if (*pdwSize < size) {
|
if (*pdwSize < size) {
|
||||||
*pdwSize = size;
|
*pdwSize = size;
|
||||||
ret = ERROR_INSUFFICIENT_BUFFER;
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
||||||
|
|
|
@ -1112,9 +1112,12 @@ DWORD getUdpTable(PMIB_UDPTABLE *ppUdpTable, HANDLE heap, DWORD flags)
|
||||||
ret = ERROR_INVALID_PARAMETER;
|
ret = ERROR_INVALID_PARAMETER;
|
||||||
else {
|
else {
|
||||||
DWORD numEntries = getNumUdpEntries();
|
DWORD numEntries = getNumUdpEntries();
|
||||||
PMIB_UDPTABLE table = HeapAlloc(heap, flags,
|
DWORD size = sizeof(MIB_UDPTABLE);
|
||||||
sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW));
|
PMIB_UDPTABLE table;
|
||||||
|
|
||||||
|
if (numEntries > 1)
|
||||||
|
size += (numEntries - 1) * sizeof(MIB_UDPROW);
|
||||||
|
table = HeapAlloc(heap, flags, size);
|
||||||
if (table) {
|
if (table) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue