From patchwork Fri Jan 26 05:05:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selva Nair X-Patchwork-Id: 218 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director6.mail.ord1d.rsapps.net ([172.30.191.6]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id uzYkH/lRa1oXOgAAgoeIoA for ; Fri, 26 Jan 2018 11:06:17 -0500 Received: from proxy3.mail.ord1d.rsapps.net ([172.30.191.6]) by director6.mail.ord1d.rsapps.net (Dovecot) with LMTP id E+GkHvlRa1rvRgAAhgvE6Q ; Fri, 26 Jan 2018 11:06:17 -0500 Received: from smtp33.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy3.mail.ord1d.rsapps.net (Dovecot) with LMTP id +lGRBvlRa1oDbQAA7WKfLA ; Fri, 26 Jan 2018 11:06:17 -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: smtp33.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: d72f3b60-02b2-11e8-9cd1-525400041ef2-1-1 Received: from [216.34.181.88] ([216.34.181.88:62736] helo=lists.sourceforge.net) by smtp33.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 8F/34-25052-9F15B6A5; Fri, 26 Jan 2018 11:06:17 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1ef6Vc-0001xS-Cq; Fri, 26 Jan 2018 16:05:44 +0000 Received: from sfi-mx-4.v28.ch3.sourceforge.com ([172.29.28.194] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1ef6Vb-0001xL-1K for openvpn-devel@lists.sourceforge.net; Fri, 26 Jan 2018 16:05:43 +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=iAm/CHz5NggKI+98xw8szwpLgECc2vWjfJpc6LAUwQk=; b=LcNVXvOa/5dN64aABNeNzyCmxJ LtuNo13eX/Jk9riLyhu2BXuQIsYnzaPydu3JA63d3nRgKrEHiIXqmT/GnDGag4jci3tJVftgYoHdC YmGkP5hGpt8hyDl+EY2I32hmadXO0V7Op+VfX2rn+9XYbdeEbtvECTxHNBK1u73Cpenk=; 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=iAm/CHz5NggKI+98xw8szwpLgECc2vWjfJpc6LAUwQk=; b=akgntjx5mUCB+KA1HJdKnO6ium 0QzeWwkgSQkR4cxHkovTLSKZV6kw2+zuY+M9OUzPMsVgn12TjK0i6vlG389u+dJeIKTr//WZzN8Vh yYneacLveHHRUX5wf3KK9SV7T8cDVfXv2umiV89e0sE7z0X8oyT0JTGZ69ZWud5n2/k0=; Received: from mail-it0-f66.google.com ([209.85.214.66]) by sfi-mx-4.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) id 1ef6Va-00014K-6Y for openvpn-devel@lists.sourceforge.net; Fri, 26 Jan 2018 16:05:42 +0000 Received: by mail-it0-f66.google.com with SMTP id u62so1073094ita.2 for ; Fri, 26 Jan 2018 08:05:42 -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=iAm/CHz5NggKI+98xw8szwpLgECc2vWjfJpc6LAUwQk=; b=HSnbN+rrT542VEPjrTikp1MdvtvKRRlH8LpojN18tJ3c2e/KPSynjrX50AZxw/zOEd CFe/9iD6J8urvq2A+yd+kGiVzcY0MI8XoEbbT3j4XOUphyG5QBAXJsJsytB9iMJBVHy2 3UQNKSAN2HDra71YgJR+MpP3Z0/2vPRskk4LzJBGzXc9YUr9VJn4zGYR4aKd65CUaum0 CfLI8g0t1yCiuZXToGTo+gfUnLBziCJryODw8pBzG+ca3h9bFaF4nE/FwwlO/h7S5F4O 4Ph8CEDIcLpfbTFhUJMArxwez/pVX6Z7kEYoVO5zbr7Ukpm0ffUBkFRDkGCIA12TLTlL zfSA== 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=iAm/CHz5NggKI+98xw8szwpLgECc2vWjfJpc6LAUwQk=; b=rPxWJqmkOa2+Em7OsRDTUH18JaeMcc+y+55ngt1tHZ2h1/XaqGdLddA+ZrTTX4bLZh AlG3SV9d832LMUc2G77SEVVq1c5XPxp2m4vXdFar3ogzde4o2C6TgKxoVHxwix0Hbzfv j/XRZN+5csRvFV9Q7IdTY8r+CPYbVtcZwScOuLT+WhXFMTm+ml1D+7Y4iGRy/trh1i5e YfRO1oRVSMi2Vi9wl/+BSUGng76prfpMlxTG6CbuiU+EZGpDay/4DbtswxbkcN51DNFX HJcyDImPEM/X1zoSEauumTvoFwMCmwyrG39L0ROalPkQprPgLJ8+tVxizhwf7amYPgnt l9wQ== X-Gm-Message-State: AKwxytdmrYHUyX5VPTZNcuFGYSsiTmGjxgNNrZIP+YBj2o+T9YTsuB52 UDEiK1+8cCOC6aQMya8PXxOfQfoD X-Google-Smtp-Source: AH8x226DGZebgAU+Kugi0DjVsFuoT1FGEfntmhsOcLQqsJEKk+DJ5m6P7mKRgUfg6vpMxhmecc1JbA== X-Received: by 10.36.61.205 with SMTP id n196mr18056302itn.95.1516982736798; Fri, 26 Jan 2018 08:05:36 -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 k75sm678872iod.27.2018.01.26.08.05.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jan 2018 08:05:36 -0800 (PST) From: selva.nair@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Fri, 26 Jan 2018 11:05:32 -0500 Message-Id: <1516982732-24145-1-git-send-email-selva.nair@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: 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.66 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 0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1ef6Va-00014K-6Y Subject: [Openvpn-devel] [PATCH v2 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: Gert Doering Acked-by: Gert Doering --- v2: Same as the ACK-ed v1 but the extra newline removed. src/openvpn/cryptoapi.c | 62 +++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c index f155123..0349191 100644 --- a/src/openvpn/cryptoapi.c +++ b/src/openvpn/cryptoapi.c @@ -108,6 +108,31 @@ 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 +388,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 +624,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; }