iphlpapi: Don't allocate gobs of memory when the TCP entry table is empty.

This commit is contained in:
Juan Lang 2007-11-15 11:01:13 -08:00 committed by Alexandre Julliard
parent 64f61ce0cd
commit 5349c5e87b
2 changed files with 11 additions and 6 deletions

View File

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

View File

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