From patchwork Tue Jan 23 18:06:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selva Nair X-Patchwork-Id: 209 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director5.mail.ord1d.rsapps.net ([172.30.191.6]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id iyE/A5oUaFoAWAAAgoeIoA for ; Wed, 24 Jan 2018 00:07:38 -0500 Received: from proxy8.mail.ord1d.rsapps.net ([172.30.191.6]) by director5.mail.ord1d.rsapps.net (Dovecot) with LMTP id iwsZA5oUaFoieQAAsdCWiw ; Wed, 24 Jan 2018 00:07:38 -0500 Received: from smtp32.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy8.mail.ord1d.rsapps.net (Dovecot) with LMTP id 8jLlAZoUaFouUwAAGdz6CA ; Wed, 24 Jan 2018 00:07:38 -0500 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.34.181.88] Authentication-Results: smtp32.gate.ord1d.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; 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; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Classification-ID: 7ee78e02-00c4-11e8-a67f-52540099eaf5-1-1 Received: from [216.34.181.88] ([216.34.181.88:28170] helo=lists.sourceforge.net) by smtp32.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 72/39-05604-994186A5; Wed, 24 Jan 2018 00:07:37 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eeDGb-0006PU-Co; Wed, 24 Jan 2018 05:06:33 +0000 Received: from sfi-mx-4.v28.ch3.sourceforge.com ([172.29.28.194] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eeDGa-0006P7-CR for openvpn-devel@lists.sourceforge.net; Wed, 24 Jan 2018 05:06:32 +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=XIxD68Ausd/XCTD1bHZStMwJhoPq103IuZL5BaU8kV0=; b=lfE7eiSWXJMJagdqkI0SlisDrZ jwSmETxIQ+WoVVWeIDh/6V+W632rYHumE7VQgMi3X/vTxWgHqE9oGfErSXrYw+gurTW9gON8BrRw3 3YWONkLyuX0lb1RJ41Vc+9hldNWq3WadKF+aH8F6lXIodu/+tlYdmgAfZyA1KqV9JqJo=; 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=XIxD68Ausd/XCTD1bHZStMwJhoPq103IuZL5BaU8kV0=; b=RfoAHTJUlUsER3JQVpzkTVqn44 wMHbEX0KnCvAJaRWChYRrgeEttt4fIK3/yd0j2ZR9CbV71aeHP38paHqmzodD8wjSroi0kuNg2ISG /7iWViqEhSk3ftDuePUS6/7tw+mKQ5PxcYOPrtb5+RxPh16oh4OV19aH5grimXUdHPBE=; Received: from mail-it0-f65.google.com ([209.85.214.65]) by sfi-mx-4.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) id 1eeDGZ-0005Wm-Ix for openvpn-devel@lists.sourceforge.net; Wed, 24 Jan 2018 05:06:32 +0000 Received: by mail-it0-f65.google.com with SMTP id u62so3738142ita.2 for ; Tue, 23 Jan 2018 21:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XIxD68Ausd/XCTD1bHZStMwJhoPq103IuZL5BaU8kV0=; b=B/419HMFZsW1dO2SSDAhYKnKnX3tPEAzc1OZ9Ty91R1DDrnQm4mSBcpzykKVvAIZmV knFQcivj/IM/L3wT7b0vTCaEivsNRYwa+MmQoBp/TaJlixow44WC5Hb+5LxSDwMeCYna llFNA4pXeqF7aSgQdLZvmtC5d+K7wqdBs+nuekHuCNxo3+608mm+PwPQgoM0AF3hJ0RI aNAhaReE4MFcQtF3Z9zeBJflB53IBh8j7StudY5HVizC9RuMA2WpnNjEXDO6IGuIMECB Y+oQ5pXufswQtKo53RZG132H5f9X002LvYXH0o0QpGklB+sgNek60qJ8foPqfYlOC0Af tfqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XIxD68Ausd/XCTD1bHZStMwJhoPq103IuZL5BaU8kV0=; b=XxNk6u31nnqZSNmxDxV2porFZnvr87t91rhsMdxuqKhsymHF67RrAHbHltigBImE3m RdWgQhUFEKSzckHS7Yhch74hWRNn7cIewwTx04I8QdOFhpgw2ho1ScHYE3tpPjfrjBsQ u/WClcSTnnoSUd751UvlKWghprBrimEEAggt/ktsWS/bl/VsOa5rROYnnpn1ia/LYRjF NjlQ+Rat13Q1EwsxQM/YUqMQkdsTwesA4vmoAU95XL9X9w9ELQJFi8UJaKm969SrjzY+ sS+BTpb2c36mKSiW8Fj39USsfCjivkiT+GJCUOqSmPRK1Y1i3Z0BQS6otujzl7E6yJbW 5Bsw== X-Gm-Message-State: AKwxytfpYNpxvU8l7OwxlhNSmZKRt0p9Lct/L1ILC8eypO/9uW9dWejA G+XeMr0v/4X9pDtYhvbRAdKfCakJ X-Google-Smtp-Source: AH8x227HGFFxyFj13SVq1dhL4seyUQg8uHoZCNwZjq/0DxQT/3zG351dHkV6opkr+m3fByT50JHACQ== X-Received: by 10.36.205.133 with SMTP id l127mr7088889itg.98.1516770386166; Tue, 23 Jan 2018 21:06:26 -0800 (PST) Received: from saturn.home.sansel.ca (CPE40167ea0e1c2-CM788df74daaa0.cpe.net.cable.rogers.com. [99.228.215.92]) by smtp.gmail.com with ESMTPSA id 140sm289669itx.3.2018.01.23.21.06.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Jan 2018 21:06:25 -0800 (PST) From: selva.nair@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Wed, 24 Jan 2018 00:06:19 -0500 Message-Id: <1516770381-29466-2-git-send-email-selva.nair@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1516770381-29466-1-git-send-email-selva.nair@gmail.com> References: <1516770381-29466-1-git-send-email-selva.nair@gmail.com> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (selva.nair[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.214.65 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1eeDGZ-0005Wm-Ix Subject: [Openvpn-devel] [PATCH 1/3] Move code to free cd to a function CAPI_DATA_free() 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 From: Selva Nair - Avoids code-repetition especially so when support for more key types are added. Signed-off-by: Selva Nair Acked-by: Steffan Karger --- src/openvpn/cryptoapi.c | 63 ++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c index f155123..00e78b6 100644 --- a/src/openvpn/cryptoapi.c +++ b/src/openvpn/cryptoapi.c @@ -108,6 +108,32 @@ typedef struct _CAPI_DATA { BOOL free_crypt_prov; } CAPI_DATA; +static void +CAPI_DATA_free(CAPI_DATA *cd) +{ + if (!cd) + { + return; + } + if (cd->free_crypt_prov && cd->crypt_prov) + { + if (cd->key_spec == CERT_NCRYPT_KEY_SPEC) + { + NCryptFreeObject(cd->crypt_prov); + } + else + { + CryptReleaseContext(cd->crypt_prov, 0); + } + } + if (cd->cert_context) + { + CertFreeCertificateContext(cd->cert_context); + } + free(cd); +} + + static char * ms_error_text(DWORD ms_err) { @@ -363,22 +389,7 @@ finish(RSA *rsa) { return 0; } - if (cd->crypt_prov && cd->free_crypt_prov) - { - if (cd->key_spec == CERT_NCRYPT_KEY_SPEC) - { - NCryptFreeObject(cd->crypt_prov); - } - else - { - CryptReleaseContext(cd->crypt_prov, 0); - } - } - if (cd->cert_context) - { - CertFreeCertificateContext(cd->cert_context); - } - free(cd); + CAPI_DATA_free(cd); RSA_meth_free((RSA_METHOD*) rsa_meth); return 1; } @@ -614,25 +625,7 @@ err: { free(my_rsa_method); } - if (cd) - { - if (cd->free_crypt_prov && cd->crypt_prov) - { - if (cd->key_spec == CERT_NCRYPT_KEY_SPEC) - { - NCryptFreeObject(cd->crypt_prov); - } - else - { - CryptReleaseContext(cd->crypt_prov, 0); - } - } - if (cd->cert_context) - { - CertFreeCertificateContext(cd->cert_context); - } - free(cd); - } + CAPI_DATA_free(cd); } return 0; }