From patchwork Fri Oct 23 00:34:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1520 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.27.255.8]) by backend41.mail.ord1d.rsapps.net with LMTP id eNRPHRDAkl/PWQAAqwncew (envelope-from ) for ; Fri, 23 Oct 2020 07:35:44 -0400 Received: from proxy6.mail.iad3a.rsapps.net ([172.27.255.8]) by director9.mail.ord1d.rsapps.net with LMTP id SKMaHRDAkl9OFQAAalYnBA (envelope-from ) for ; Fri, 23 Oct 2020 07:35:44 -0400 Received: from smtp24.gate.iad3a ([172.27.255.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy6.mail.iad3a.rsapps.net with LMTPS id wJs8FxDAkl9/VwAA8udqhg (envelope-from ) for ; Fri, 23 Oct 2020 07:35:44 -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: smtp24.gate.iad3a.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=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: e10e2e26-1523-11eb-b29f-5254009f6f51-1-1 Received: from [216.105.38.7] ([216.105.38.7:38430] helo=lists.sourceforge.net) by smtp24.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 56/A4-08455-D00C29F5; Fri, 23 Oct 2020 07:35:41 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kVvLQ-0002Hh-1i; Fri, 23 Oct 2020 11:34:52 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVvLL-0002HC-Qg for openvpn-devel@lists.sourceforge.net; Fri, 23 Oct 2020 11:34:47 +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:To: From:Sender:Reply-To:Cc: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=pzvGf2r1MPOv+YkY0F8T9eTwebyHz0rNNy52BbrepO0=; b=DH/UHEh/LIPdC24j0hB/4aH7bA D80y8Zfs1hYHQrF7nnmc5n1oEMRHt8Q1wmIJ+rn68vaKC0rlFGjeRvI9+97TG0ruNHSx/Nw7+nTAh cdc8KSFT+JDk9qvJCcntHHL7gmd8y/tV9wA/YKzNvLjrhn+JVQAUnsjCAJVbx33dbrdA=; 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:To:From:Sender:Reply-To:Cc :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=pzvGf2r1MPOv+YkY0F8T9eTwebyHz0rNNy52BbrepO0=; b=B6PVSLZlAY83gTsCAgi834L8Oq l4dTpRRNQVVFNMJe4PQdZlT0biVit/rfpBhZ9WRQEQ8tHegixxM4CASPC/A4XiOnYmJSKlS2lwA2z Ix5NpjCGiS9cINxRWlcznyjj256E2gwVzBEmpyzjnCVxEjWRuvDoH3FMnZDBDqE9++2M=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kVvLF-00A1Lx-K2 for openvpn-devel@lists.sourceforge.net; Fri, 23 Oct 2020 11:34:47 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1kVvL5-000J9z-W2 for openvpn-devel@lists.sourceforge.net; Fri, 23 Oct 2020 13:34:31 +0200 Received: (nullmailer pid 26744 invoked by uid 10006); Fri, 23 Oct 2020 11:34:31 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Fri, 23 Oct 2020 13:34:29 +0200 Message-Id: <20201023113431.26691-3-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201023113431.26691-1-arne@rfc2549.org> References: <20201023113431.26691-1-arne@rfc2549.org> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rfc2549.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Headers-End: 1kVvLF-00A1Lx-K2 Subject: [Openvpn-devel] [PATCH 3/5] Align reliable_free with other free methods to accept NULL 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: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox The semantic of most free methods is to free a pointer and all its contents and also free the pointer itself. Align reliable_free to this semantic. Also clean up the other free uses in key_state_free. Signed-off-by: Arne Schwabe Acked-by: Gert Doering --- src/openvpn/reliable.c | 5 +++++ src/openvpn/reliable.h | 4 +++- src/openvpn/ssl.c | 24 ++++-------------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/openvpn/reliable.c b/src/openvpn/reliable.c index eae1e0cb..6c1f2da1 100644 --- a/src/openvpn/reliable.c +++ b/src/openvpn/reliable.c @@ -326,12 +326,17 @@ reliable_init(struct reliable *rel, int buf_size, int offset, int array_size, bo void reliable_free(struct reliable *rel) { + if (!rel) + { + return; + } int i; for (i = 0; i < rel->size; ++i) { struct reliable_entry *e = &rel->array[i]; free_buf(&e->buf); } + free(rel); } /* no active buffers? */ diff --git a/src/openvpn/reliable.h b/src/openvpn/reliable.h index 688c65c8..a84d4290 100644 --- a/src/openvpn/reliable.h +++ b/src/openvpn/reliable.h @@ -192,7 +192,9 @@ bool reliable_ack_write(struct reliable_ack *ack, void reliable_init(struct reliable *rel, int buf_size, int offset, int array_size, bool hold); /** - * Free allocated memory associated with a reliable structure. + * Free allocated memory associated with a reliable structure and the pointer + * itself. + * Does nothing if rel is NULL. * * @param rel The reliable structured to clean up. */ diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 87b51d96..7a3eb146 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -969,27 +969,11 @@ key_state_free(struct key_state *ks, bool clear) free_buf(&ks->ack_write_buf); buffer_list_free(ks->paybuf); - if (ks->send_reliable) - { - reliable_free(ks->send_reliable); - free(ks->send_reliable); - } - - if (ks->rec_reliable) - { - reliable_free(ks->rec_reliable); - free(ks->rec_reliable); - } + reliable_free(ks->send_reliable); + reliable_free(ks->rec_reliable); - if (ks->rec_ack) - { - free(ks->rec_ack); - } - - if (ks->key_src) - { - free(ks->key_src); - } + free(ks->rec_ack); + free(ks->key_src); packet_id_free(&ks->crypto_options.packet_id);