summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2020-09-03 17:29:06 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2020-09-03 17:29:06 +0000
commitb177345935d57471bfc2d8d73ac2c91d36dcc9a1 (patch)
treed4ddd82e3a2eedb0f035ade0bb2c4bd255a2c1cd
parent9597dad3de9bc3455a7b66edf7ca21e794850baa (diff)
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
-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);
}