iphlpapi: Don't allocate gobs of memory when the TCP entry table is empty.
This commit is contained in:
parent
64f61ce0cd
commit
5349c5e87b
|
@ -1579,8 +1579,10 @@ DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
|
|||
ret = ERROR_INVALID_PARAMETER;
|
||||
else {
|
||||
DWORD numEntries = getNumTcpEntries();
|
||||
DWORD size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW);
|
||||
DWORD size = sizeof(MIB_TCPTABLE);
|
||||
|
||||
if (numEntries > 1)
|
||||
size += (numEntries - 1) * sizeof(MIB_TCPROW);
|
||||
if (!pTcpTable || *pdwSize < size) {
|
||||
*pdwSize = size;
|
||||
ret = ERROR_INSUFFICIENT_BUFFER;
|
||||
|
@ -1588,8 +1590,9 @@ DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
|
|||
else {
|
||||
ret = getTcpTable(&pTcpTable, numEntries, 0, 0);
|
||||
if (!ret) {
|
||||
size = sizeof(MIB_TCPTABLE) + (pTcpTable->dwNumEntries - 1) *
|
||||
sizeof(MIB_TCPROW);
|
||||
size = sizeof(MIB_TCPTABLE);
|
||||
if (numEntries > 1)
|
||||
size += (numEntries - 1) * sizeof(MIB_TCPROW);
|
||||
*pdwSize = size;
|
||||
|
||||
if (bOrder)
|
||||
|
|
|
@ -1212,9 +1212,11 @@ DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, DWORD maxEntries, HANDLE heap,
|
|||
|
||||
if (!*ppTcpTable)
|
||||
{
|
||||
*ppTcpTable = HeapAlloc (heap, flags,
|
||||
sizeof (MIB_TCPTABLE) +
|
||||
(numEntries - 1) * sizeof (MIB_TCPROW));
|
||||
DWORD size = sizeof(MIB_TCPTABLE);
|
||||
|
||||
if (numEntries > 1)
|
||||
size += (numEntries - 1) * sizeof (MIB_TCPROW);
|
||||
*ppTcpTable = HeapAlloc (heap, flags, size);
|
||||
if (!*ppTcpTable)
|
||||
{
|
||||
ERR ("Out of memory!\n");
|
||||
|
|
Loading…
Reference in New Issue