From patchwork Wed Jun 13 02:28:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 369 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net (Dovecot) with LMTP id Hts9AUIOIVs3aQAAIUCqbw for ; Wed, 13 Jun 2018 08:29:54 -0400 Received: from proxy16.mail.iad3b.rsapps.net ([172.31.255.6]) by director7.mail.ord1d.rsapps.net (Dovecot) with LMTP id GVhZFkIOIVtMPAAAovjBpQ ; Wed, 13 Jun 2018 08:29:54 -0400 Received: from smtp36.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy16.mail.iad3b.rsapps.net with LMTP id yO1ZJ0IOIVtSLwAAPj+4aA ; Wed, 13 Jun 2018 08:29:54 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp36.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=unstable.cc X-Suspicious-Flag: YES X-Classification-ID: 788e1d0a-6f05-11e8-95ab-5254003a7283-1-1 Received: from [216.105.38.7] ([216.105.38.7:64297] helo=lists.sourceforge.net) by smtp36.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 4B/D6-06288-04E012B5; Wed, 13 Jun 2018 08:29:53 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1fT4tl-0006vi-Fa; Wed, 13 Jun 2018 12:29:13 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fT4tk-0006vc-4C for openvpn-devel@lists.sourceforge.net; Wed, 13 Jun 2018 12:29:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=4oLkNI4DeYEaofuxkQXKHJ2B93L4XC8WjzB4EQmqhd0=; b=axcN7qbE6h71FjfTpPxN6WlQ/6 5hMkBaTyHRUxTW3haVwwmwTcfIvcvip73a4IM5j5tQbdku6ORaw5EzJjt6qeQpGYv3qOn/UHsevgb 86t2+hqHV4J97yoLV3aHKtKq6Frf+PA0EPOCEw1zhv8Qcp423i7wePAWQJ/iuFfmI5jg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=4oLkNI4DeYEaofuxkQXKHJ2B93L4XC8WjzB4EQmqhd0=; b=IxCMJNicd2YZoknAdMA/VBJqFY 9RkzJss34OWHXVHlBYkBJZcXrJxZx3go9CTMNZmzNDqG33K2n/V3xcFJUgI0gYQe992IppMTz6C7m flQMpOs4nPyutVBbl1HAKpecqCXYlarKhU5Q2Vyal46kIb/CKLA2GjuShAy7x8VaJE9s=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1fT4ti-005sOS-Ni for openvpn-devel@lists.sourceforge.net; Wed, 13 Jun 2018 12:29:12 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Wed, 13 Jun 2018 20:28:22 +0800 Message-Id: <20180613122824.4207-2-a@unstable.cc> In-Reply-To: <20180613122824.4207-1-a@unstable.cc> References: <20180613122824.4207-1-a@unstable.cc> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [5.148.176.60 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1fT4ti-005sOS-Ni Subject: [Openvpn-devel] [PATCH v2 1/3] tun: ensure gc and argv are properly handled X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Antonio Quartulli MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Antonio Quartulli 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 Acked-by: Gert Doering --- Changes from v1: - remove gc_arena at all when not used src/openvpn/tun.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 3eb0f78a..72506c4b 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -2600,7 +2600,6 @@ close_tun(struct tuntap *tt) } else if (tt) { - struct gc_arena gc = gc_new(); struct argv argv = argv_new(); /* setup command, close tun dev (clears tt->actual_name!), run command @@ -2615,6 +2614,7 @@ close_tun(struct tuntap *tt) openvpn_execve_check(&argv, NULL, 0, "OpenBSD 'destroy tun interface' failed (non-critical)"); free(tt); + argv_reset(&argv); } } @@ -2685,7 +2685,6 @@ close_tun(struct tuntap *tt) } else if (tt) { - struct gc_arena gc = gc_new(); struct argv argv = argv_new(); /* setup command, close tun dev (clears tt->actual_name!), run command @@ -2700,6 +2699,7 @@ close_tun(struct tuntap *tt) openvpn_execve_check(&argv, NULL, 0, "NetBSD 'destroy tun interface' failed (non-critical)"); free(tt); + argv_reset(&argv); } } @@ -2837,6 +2837,7 @@ close_tun(struct tuntap *tt) openvpn_execve_check(&argv, NULL, 0, "FreeBSD 'destroy tun interface' failed (non-critical)"); free(tt); + argv_reset(&argv); } } @@ -3308,6 +3309,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun env_set_add( es, "ODMDIR=/etc/objrepos" ); openvpn_execve_check(&argv, es, S_FATAL, "AIX 'create tun interface' failed"); env_set_destroy(es); + argv_reset(&argv); } else { @@ -3333,7 +3335,6 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun void close_tun(struct tuntap *tt) { - struct gc_arena gc = gc_new(); struct argv argv = argv_new(); struct env_set *es = env_set_create(NULL); @@ -3362,6 +3363,7 @@ close_tun(struct tuntap *tt) free(tt); env_set_destroy(es); + argv_reset(&argv); } int