diff options
author | tb <> | 2023-12-25 21:41:19 +0000 |
---|---|---|
committer | tb <> | 2023-12-25 21:41:19 +0000 |
commit | bd5929d47ed5d4ecddaca010d10d643cb23d9e97 (patch) | |
tree | 4c1b7b90b3af9d398ba571d3f2be295ac7e70fa2 /src/lib | |
parent | c4be2856518cdc4682a716b0db9c070fc255ea75 (diff) | |
download | openbsd-bd5929d47ed5d4ecddaca010d10d643cb23d9e97.tar.gz openbsd-bd5929d47ed5d4ecddaca010d10d643cb23d9e97.tar.bz2 openbsd-bd5929d47ed5d4ecddaca010d10d643cb23d9e97.zip |
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
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/evp/p_lib.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c index f819717cbc..3eba5af298 100644 --- a/src/lib/libcrypto/evp/p_lib.c +++ b/src/lib/libcrypto/evp/p_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p_lib.c,v 1.46 2023/12/25 21:37:26 tb Exp $ */ | 1 | /* $OpenBSD: p_lib.c,v 1.47 2023/12/25 21:41:19 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -225,21 +225,17 @@ evp_pkey_free_pkey_ptr(EVP_PKEY *pkey) | |||
225 | } | 225 | } |
226 | 226 | ||
227 | void | 227 | void |
228 | EVP_PKEY_free(EVP_PKEY *x) | 228 | EVP_PKEY_free(EVP_PKEY *pkey) |
229 | { | 229 | { |
230 | int i; | 230 | if (pkey == NULL) |
231 | |||
232 | if (x == NULL) | ||
233 | return; | 231 | return; |
234 | 232 | ||
235 | i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY); | 233 | if (CRYPTO_add(&pkey->references, -1, CRYPTO_LOCK_EVP_PKEY) > 0) |
236 | if (i > 0) | ||
237 | return; | 234 | return; |
238 | 235 | ||
239 | evp_pkey_free_pkey_ptr(x); | 236 | evp_pkey_free_pkey_ptr(pkey); |
240 | if (x->attributes) | 237 | sk_X509_ATTRIBUTE_pop_free(pkey->attributes, X509_ATTRIBUTE_free); |
241 | sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); | 238 | freezero(pkey, sizeof(*pkey)); |
242 | free(x); | ||
243 | } | 239 | } |
244 | 240 | ||
245 | /* Setup a public key ASN1 method from a NID or a string. | 241 | /* Setup a public key ASN1 method from a NID or a string. |