Juan Lang : iphlpapi: Don' t allocate gobs of memory when the ARP table is empty.

Alexandre Julliard julliard at winehq.org
Fri Nov 16 08:31:18 CST 2007


Module: wine
Branch: master
Commit: 72a59de299c307359599d9a26c6dd265c4623b44
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=72a59de299c307359599d9a26c6dd265c4623b44

Author: Juan Lang <juan.lang at gmail.com>
Date:   Thu Nov 15 11:03:25 2007 -0800

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

---

 dlls/iphlpapi/iphlpapi_main.c |   10 ++++++----
 dlls/iphlpapi/ipstats.c       |    7 +++++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 9ba742b..92df631 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -1289,9 +1289,10 @@ DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOr
     ret = ERROR_INVALID_PARAMETER;
   else {
     DWORD numEntries = getNumArpEntries();
-    ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
-     sizeof(MIB_IPNETROW);
+    ULONG size = sizeof(MIB_IPNETTABLE);
 
+    if (numEntries > 1)
+      size += (numEntries - 1) * sizeof(MIB_IPNETROW);
     if (!pIpNetTable || *pdwSize < size) {
       *pdwSize = size;
       ret = ERROR_INSUFFICIENT_BUFFER;
@@ -1301,8 +1302,9 @@ DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOr
 
       ret = getArpTable(&table, GetProcessHeap(), 0);
       if (!ret) {
-        size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
-         sizeof(MIB_IPNETROW);
+        size = sizeof(MIB_IPNETTABLE);
+        if (table->dwNumEntries > 1)
+          size += (table->dwNumEntries - 1) * sizeof(MIB_IPNETROW);
         if (*pdwSize < size) {
           *pdwSize = size;
           ret = ERROR_INSUFFICIENT_BUFFER;
diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index b17b0da..3605d64 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -1009,9 +1009,12 @@ DWORD getArpTable(PMIB_IPNETTABLE *ppIpNetTable, HANDLE heap, DWORD flags)
     ret = ERROR_INVALID_PARAMETER;
   else {
     DWORD numEntries = getNumArpEntries();
-    PMIB_IPNETTABLE table = HeapAlloc(heap, flags,
-     sizeof(MIB_IPNETTABLE) + (numEntries - 1) * sizeof(MIB_IPNETROW));
+    DWORD size = sizeof(MIB_IPNETTABLE);
+    PMIB_IPNETTABLE table;
 
+    if (numEntries > 1)
+      size += (numEntries - 1) * sizeof(MIB_IPNETROW);
+    table = HeapAlloc(heap, flags, size);
     if (table) {
       FILE *fp;
 




More information about the wine-cvs mailing list