Browse code

tun: ensure gc and argv are properly handled

Everytime a argv object is initialized with argv_new(), it has
to be released with argv_reset() once not needed anymore.

Ensure this kind of objects are always properly released to avoid
memory leaks.

At the same time, remove those gc_arena objects that are initialized
but never used/released.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>

Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20180613122824.4207-2-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17044.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Antonio Quartulli authored on 2018/06/13 21:28:22
Showing 1 changed files
... ...
@@ -2600,7 +2600,6 @@ close_tun(struct tuntap *tt)
2600 2600
     }
2601 2601
     else if (tt)
2602 2602
     {
2603
-        struct gc_arena gc = gc_new();
2604 2603
         struct argv argv = argv_new();
2605 2604
 
2606 2605
         /* setup command, close tun dev (clears tt->actual_name!), run command
... ...
@@ -2615,6 +2614,7 @@ close_tun(struct tuntap *tt)
2615 2615
         openvpn_execve_check(&argv, NULL, 0, "OpenBSD 'destroy tun interface' failed (non-critical)");
2616 2616
 
2617 2617
         free(tt);
2618
+        argv_reset(&argv);
2618 2619
     }
2619 2620
 }
2620 2621
 
... ...
@@ -2685,7 +2685,6 @@ close_tun(struct tuntap *tt)
2685 2685
     }
2686 2686
     else if (tt)
2687 2687
     {
2688
-        struct gc_arena gc = gc_new();
2689 2688
         struct argv argv = argv_new();
2690 2689
 
2691 2690
         /* setup command, close tun dev (clears tt->actual_name!), run command
... ...
@@ -2700,6 +2699,7 @@ close_tun(struct tuntap *tt)
2700 2700
         openvpn_execve_check(&argv, NULL, 0, "NetBSD 'destroy tun interface' failed (non-critical)");
2701 2701
 
2702 2702
         free(tt);
2703
+        argv_reset(&argv);
2703 2704
     }
2704 2705
 }
2705 2706
 
... ...
@@ -2837,6 +2837,7 @@ close_tun(struct tuntap *tt)
2837 2837
         openvpn_execve_check(&argv, NULL, 0, "FreeBSD 'destroy tun interface' failed (non-critical)");
2838 2838
 
2839 2839
         free(tt);
2840
+        argv_reset(&argv);
2840 2841
     }
2841 2842
 }
2842 2843
 
... ...
@@ -3308,6 +3309,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
3308 3308
         env_set_add( es, "ODMDIR=/etc/objrepos" );
3309 3309
         openvpn_execve_check(&argv, es, S_FATAL, "AIX 'create tun interface' failed");
3310 3310
         env_set_destroy(es);
3311
+        argv_reset(&argv);
3311 3312
     }
3312 3313
     else
3313 3314
     {
... ...
@@ -3333,7 +3335,6 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
3333 3333
 void
3334 3334
 close_tun(struct tuntap *tt)
3335 3335
 {
3336
-    struct gc_arena gc = gc_new();
3337 3336
     struct argv argv = argv_new();
3338 3337
     struct env_set *es = env_set_create(NULL);
3339 3338
 
... ...
@@ -3362,6 +3363,7 @@ close_tun(struct tuntap *tt)
3362 3362
 
3363 3363
     free(tt);
3364 3364
     env_set_destroy(es);
3365
+    argv_reset(&argv);
3365 3366
 }
3366 3367
 
3367 3368
 int