Commit 5349c5e8 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

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

parent 64f61ce0
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment