From: tb Date: Mon, 25 Dec 2023 21:41:19 +0000 (+0000) Subject: Rework EVP_PKEY_free() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=8ae31416c90de5328547584b03014c0dbd4f7547;p=openbsd Rework EVP_PKEY_free() Use pkey instead of x, remove the pointless variable i, no need to check for NULL before sk_X509_ATTRIBUTE_pop_free(), switch to freezero() to leave fewer invalid pointers around. ok jsing --- diff --git a/lib/libcrypto/evp/p_lib.c b/lib/libcrypto/evp/p_lib.c index f819717cbcb..3eba5af298b 100644 --- a/lib/libcrypto/evp/p_lib.c +++ b/lib/libcrypto/evp/p_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: p_lib.c,v 1.46 2023/12/25 21:37:26 tb Exp $ */ +/* $OpenBSD: p_lib.c,v 1.47 2023/12/25 21:41:19 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -225,21 +225,17 @@ evp_pkey_free_pkey_ptr(EVP_PKEY *pkey) } void -EVP_PKEY_free(EVP_PKEY *x) +EVP_PKEY_free(EVP_PKEY *pkey) { - int i; - - if (x == NULL) + if (pkey == NULL) return; - i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY); - if (i > 0) + if (CRYPTO_add(&pkey->references, -1, CRYPTO_LOCK_EVP_PKEY) > 0) return; - evp_pkey_free_pkey_ptr(x); - if (x->attributes) - sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); - free(x); + evp_pkey_free_pkey_ptr(pkey); + sk_X509_ATTRIBUTE_pop_free(pkey->attributes, X509_ATTRIBUTE_free); + freezero(pkey, sizeof(*pkey)); } /* Setup a public key ASN1 method from a NID or a string.