Skip to contentSkip to conversation

delete_routes(_ipv6): avoid memleak if RT_DEFINED is not set

PATCH In review Antonio Quartulli 2 participants 2 messages Sep 17, 2022 – Sep 18, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 delete_routes(_ipv6): avoid memleak if RT_DEFINED is not set

In this case the function would exit without releasing the argv object initialized via argv_new().

Move initialization of argv after thic check is performed.

While at it, also move the declaration of gc and initizlize it with gc_new().

---
 src/openvpn/route.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
src/openvpn/route.c +4 -6
index 7eaf1121..ded8fec8 100644
@@ -2145,8 +2145,6 @@ delete_route(struct route_ipv4 *r,
              const struct env_set *es,
              openvpn_net_ctx_t *ctx)
 {
-    struct gc_arena gc;
-    struct argv argv = argv_new();
 #if !defined(TARGET_LINUX)
     const char *network;
 #if !defined(TARGET_AIX)
@@ -2165,7 +2163,8 @@ delete_route(struct route_ipv4 *r,
         return;
     }
 
-    gc_init(&gc);
+    struct gc_arena gc = gc_new();
+    struct argv argv = argv_new();
 
 #if !defined(TARGET_LINUX)
     network = print_in_addr_t(r->network, 0, &gc);
@@ -2336,8 +2335,6 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt,
                   unsigned int flags, const struct env_set *es,
                   openvpn_net_ctx_t *ctx)
 {
-    struct gc_arena gc;
-    struct argv argv = argv_new();
     const char *network;
 #if !defined(TARGET_LINUX)
     const char *gateway;
@@ -2360,7 +2357,8 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt,
     }
 #endif
 
-    gc_init(&gc);
+    struct gc_arena gc = gc_new();
+    struct argv argv = argv_new();
 
     network = print_in6_addr( r6->network, 0, &gc);
 #if !defined(TARGET_LINUX)
Signature · 1 line
2.35.1
Acked-by on v1 1/1
#1 lore raw

Thanks for spotting this and sending a patch.

Not sure why this was fixed for add_route*() in commit a11bea18b1c93 (and then made more pretty in 903e2cf5c1), but forgotten in delete_route*()

Tested with a basic t_client test with ipv4 + ipv6 routes.

Your patch has been applied to the master branch.

commit 5ac33a88b10584c3e52dc0c01dad2571b75be239

Author: Antonio Quartulli
Date:   Sun Sep 18 00:42:27 2022 +0200
     delete_routes(_ipv6): avoid memleak if RT_DEFINED is not set

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg25245.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering