Juan Lang : iphlpapi: Don' t allocate gobs of memory if the IP address table is empty.
Alexandre Julliard
julliard at winehq.org
Fri Nov 16 08:31:18 CST 2007
Module: wine
Branch: master
Commit: e1a836933f3ca25d8033cedb67a04df845d69750
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e1a836933f3ca25d8033cedb67a04df845d69750
Author: Juan Lang <juan.lang at gmail.com>
Date: Thu Nov 15 11:06:07 2007 -0800
iphlpapi: Don't allocate gobs of memory if the IP address table is empty.
---
dlls/iphlpapi/ifenum.c | 7 +++++--
dlls/iphlpapi/iphlpapi_main.c | 8 ++++----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/dlls/iphlpapi/ifenum.c b/dlls/iphlpapi/ifenum.c
index 1ae70df..0a74ef6 100644
--- a/dlls/iphlpapi/ifenum.c
+++ b/dlls/iphlpapi/ifenum.c
@@ -746,8 +746,11 @@ DWORD getIPAddrTable(PMIB_IPADDRTABLE *ppIpAddrTable, HANDLE heap, DWORD flags)
ret = enumIPAddresses(&numAddresses, &ifc);
if (!ret)
{
- *ppIpAddrTable = HeapAlloc(heap, flags, sizeof(MIB_IPADDRTABLE) +
- (numAddresses - 1) * sizeof(MIB_IPADDRROW));
+ DWORD size = sizeof(MIB_IPADDRTABLE);
+
+ if (numAddresses > 1)
+ size += (numAddresses - 1) * sizeof(MIB_IPADDRROW);
+ *ppIpAddrTable = HeapAlloc(heap, flags, size);
if (*ppIpAddrTable) {
DWORD i = 0, bcast;
caddr_t ifPtr;
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index b65276c..0de8858 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -1172,17 +1172,17 @@ DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL
ret = getIPAddrTable(&table, GetProcessHeap(), 0);
if (ret == NO_ERROR)
{
- ULONG size = sizeof(MIB_IPADDRTABLE) + (table->dwNumEntries - 1) *
- sizeof(MIB_IPADDRROW);
+ ULONG size = sizeof(MIB_IPADDRTABLE);
+ if (table->dwNumEntries > 1)
+ size += (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW);
if (!pIpAddrTable || *pdwSize < size) {
*pdwSize = size;
ret = ERROR_INSUFFICIENT_BUFFER;
}
else {
*pdwSize = size;
- memcpy(pIpAddrTable, table, sizeof(MIB_IPADDRTABLE) +
- (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW));
+ memcpy(pIpAddrTable, table, size);
if (bOrder)
qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
sizeof(MIB_IPADDRROW), IpAddrTableSorter);
More information about the wine-cvs
mailing list