Huw Davies : iphlpapi: Use the correct size to allocate the process map.

Alexandre Julliard julliard at winehq.org
Tue Aug 17 16:26:51 CDT 2021


Module: wine
Branch: master
Commit: b2600726fcb45b18e6e161640547e32df265c668
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=b2600726fcb45b18e6e161640547e32df265c668

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Aug 17 09:27:11 2021 +0100

iphlpapi: Use the correct size to allocate the process map.

The size is known at the start, so there's no need to grow it.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/iphlpapi/ipstats.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index ececfcdcecd..af14cddb0ca 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -546,7 +546,7 @@ struct pid_map
 static struct pid_map *get_pid_map( unsigned int *num_entries )
 {
     struct pid_map *map;
-    unsigned int i = 0, map_count = 16, buffer_len = 4096, process_count, pos = 0;
+    unsigned int i = 0, buffer_len = 4096, process_count, pos = 0;
     NTSTATUS ret;
     char *buffer = NULL, *new_buffer;
 
@@ -573,7 +573,7 @@ static struct pid_map *get_pid_map( unsigned int *num_entries )
         buffer = new_buffer;
     }
 
-    if (!(map = HeapAlloc( GetProcessHeap(), 0, map_count * sizeof(*map) )))
+    if (!(map = HeapAlloc( GetProcessHeap(), 0, process_count * sizeof(*map) )))
     {
         HeapFree( GetProcessHeap(), 0, buffer );
         return NULL;
@@ -586,19 +586,6 @@ static struct pid_map *get_pid_map( unsigned int *num_entries )
         pos = (pos + 7) & ~7;
         process = (const struct process_info *)(buffer + pos);
 
-        if (i >= map_count)
-        {
-            struct pid_map *new_map;
-            map_count *= 2;
-            if (!(new_map = HeapReAlloc( GetProcessHeap(), 0, map, map_count * sizeof(*map))))
-            {
-                HeapFree( GetProcessHeap(), 0, map );
-                HeapFree( GetProcessHeap(), 0, buffer );
-                return NULL;
-            }
-            map = new_map;
-        }
-
         map[i].pid = process->pid;
         map[i].unix_pid = process->unix_pid;
 




More information about the wine-cvs mailing list