Alex Henrie : ws2_32: Fix memory leak on error path in get_local_ips (cppcheck).

Alexandre Julliard julliard at winehq.org
Wed Feb 2 16:38:04 CST 2022


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

Author: Alex Henrie <alexhenrie24 at gmail.com>
Date:   Wed Feb  2 00:23:18 2022 -0700

ws2_32: Fix memory leak on error path in get_local_ips (cppcheck).

Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ws2_32/protocol.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/dlls/ws2_32/protocol.c b/dlls/ws2_32/protocol.c
index 867e9513ca2..56b7379cccc 100644
--- a/dlls/ws2_32/protocol.c
+++ b/dlls/ws2_32/protocol.c
@@ -806,7 +806,7 @@ static struct hostent *get_local_ips( char *hostname )
     IP_ADAPTER_INFO *adapters = NULL, *k;
     struct hostent *hostlist = NULL;
     MIB_IPFORWARDTABLE *routes = NULL;
-    struct route *route_addrs = NULL;
+    struct route *route_addrs = NULL, *new_route_addrs;
     DWORD adap_size, route_size, n;
 
     /* Obtain the size of the adapter list and routing table, also allocate memory */
@@ -852,9 +852,10 @@ static struct hostent *get_local_ips( char *hostname )
         }
         if (exists)
             continue;
-        route_addrs = realloc( route_addrs, (numroutes + 1) * sizeof(struct route) );
-        if (!route_addrs)
+        new_route_addrs = realloc( route_addrs, (numroutes + 1) * sizeof(struct route) );
+        if (!new_route_addrs)
             goto cleanup;
+        route_addrs = new_route_addrs;
         route_addrs[numroutes].interface = ifindex;
         route_addrs[numroutes].metric = ifmetric;
         route_addrs[numroutes].default_route = ifdefault;




More information about the wine-cvs mailing list