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) ...@@ -1579,8 +1579,10 @@ DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
ret = ERROR_INVALID_PARAMETER; ret = ERROR_INVALID_PARAMETER;
else { else {
DWORD numEntries = getNumTcpEntries(); 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) { if (!pTcpTable || *pdwSize < size) {
*pdwSize = size; *pdwSize = size;
ret = ERROR_INSUFFICIENT_BUFFER; ret = ERROR_INSUFFICIENT_BUFFER;
...@@ -1588,8 +1590,9 @@ DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder) ...@@ -1588,8 +1590,9 @@ DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
else { else {
ret = getTcpTable(&pTcpTable, numEntries, 0, 0); ret = getTcpTable(&pTcpTable, numEntries, 0, 0);
if (!ret) { if (!ret) {
size = sizeof(MIB_TCPTABLE) + (pTcpTable->dwNumEntries - 1) * size = sizeof(MIB_TCPTABLE);
sizeof(MIB_TCPROW); if (numEntries > 1)
size += (numEntries - 1) * sizeof(MIB_TCPROW);
*pdwSize = size; *pdwSize = size;
if (bOrder) if (bOrder)
......
...@@ -1212,9 +1212,11 @@ DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, DWORD maxEntries, HANDLE heap, ...@@ -1212,9 +1212,11 @@ DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, DWORD maxEntries, HANDLE heap,
if (!*ppTcpTable) if (!*ppTcpTable)
{ {
*ppTcpTable = HeapAlloc (heap, flags, DWORD size = sizeof(MIB_TCPTABLE);
sizeof (MIB_TCPTABLE) +
(numEntries - 1) * sizeof (MIB_TCPROW)); if (numEntries > 1)
size += (numEntries - 1) * sizeof (MIB_TCPROW);
*ppTcpTable = HeapAlloc (heap, flags, size);
if (!*ppTcpTable) if (!*ppTcpTable)
{ {
ERR ("Out of memory!\n"); 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