summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authortb <tb@openbsd.org>2020-09-03 17:29:05 +0000
committertb <tb@openbsd.org>2020-09-03 17:29:05 +0000
commitc033cd6a6983ebe02e56a5e63e0b07b7432fcae8 (patch)
tree5f11c68636a7fd853b3ed3602e62697261687f51 /lib
parentRemove unnecessary zeroing after recallocarray(3) (diff)
downloadwireguard-openbsd-c033cd6a6983ebe02e56a5e63e0b07b7432fcae8.tar.xz
wireguard-openbsd-c033cd6a6983ebe02e56a5e63e0b07b7432fcae8.zip
Clean up asn1/x_info.c
Instead of using malloc(3) and manually setting part of the structure to zero, part to something else and leaving the rest uninitialized, we can benefit from the fact that there's this thing called calloc(3). Moreover, all variants of free(3) in libcrypto are NULL safe. ok beck inoguchi
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/asn1/x_info.c31
1 files changed, 9 insertions, 22 deletions
diff --git a/lib/libcrypto/asn1/x_info.c b/lib/libcrypto/asn1/x_info.c
index c4769231582..9285e3e289f 100644
--- a/lib/libcrypto/asn1/x_info.c
+++ b/lib/libcrypto/asn1/x_info.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: x_info.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
+/* $OpenBSD: x_info.c,v 1.18 2020/09/03 17:29:05 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -60,48 +60,35 @@
#include <openssl/asn1.h>
#include <openssl/err.h>
-#include <openssl/evp.h>
#include <openssl/x509.h>
X509_INFO *
X509_INFO_new(void)
{
- X509_INFO *ret = NULL;
+ X509_INFO *ret;
- ret = malloc(sizeof(X509_INFO));
- if (ret == NULL) {
+ if ((ret = calloc(1, sizeof(X509_INFO))) == NULL) {
ASN1error(ERR_R_MALLOC_FAILURE);
return (NULL);
}
-
- ret->enc_cipher.cipher = NULL;
- ret->enc_len = 0;
- ret->enc_data = NULL;
-
ret->references = 1;
- ret->x509 = NULL;
- ret->crl = NULL;
- ret->x_pkey = NULL;
- return (ret);
+
+ return ret;
}
void
X509_INFO_free(X509_INFO *x)
{
- int i;
-
if (x == NULL)
return;
- i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO);
- if (i > 0)
+ if (CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO) > 0)
return;
X509_free(x->x509);
- if (x->crl != NULL)
- X509_CRL_free(x->crl);
- if (x->x_pkey != NULL)
- X509_PKEY_free(x->x_pkey);
+ X509_CRL_free(x->crl);
+ X509_PKEY_free(x->x_pkey);
free(x->enc_data);
+
free(x);
}