Skip to contentSkip to conversation

Fix (potential) memory leak in init_route_list()

PATCH In review Steffan Karger 2 participants 2 messages Nov 5, 2015 – Nov 6, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix (potential) memory leak in init_route_list()

init_route() can allocate memory in netlist, but fail in many more ways than just fail to allocate. Thus, always check and clean up netlist if needed, instead of just when init_route() succeeds.

This fix is for release/2.3 only. The master branch uses a gc to clean up the netlist, and needs a different patch for a similar problem.

Found using coverity.

---
 src/openvpn/route.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/openvpn/route.c +3 -2
index bb998cb..a3d4b71 100644
@@ -648,7 +648,7 @@ init_route_list (struct route_list *rl,
     bool warned = false;
     for (i = 0; i < opt->n; ++i)
       {
-        struct addrinfo* netlist;
+        struct addrinfo* netlist = NULL;
 	struct route_ipv4 r;
 
 	if (!init_route (&r,
@@ -675,8 +675,9 @@ init_route_list (struct route_list *rl,
 		      }
 		  }
 	      }
-            freeaddrinfo(netlist);
 	  }
+	if (netlist)
+	  freeaddrinfo(netlist);
       }
     rl->n = j;
   }
Signature · 1 line
2.5.0
#1 lore raw

ACK.

Your patch has been applied to the release/2.3 branch.

commit b155655a218686317c5d48ccbaaa6e8696820b88

Author: Steffan Karger
Date:   Thu Nov 5 23:17:01 2015 +0100
     Fix (potential) memory leak in init_route_list()

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/10442
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering