From 992067d5cd15deed65484ab2fc52daa60bb44f7a Mon Sep 17 00:00:00 2001 From: tb <> Date: Thu, 3 Sep 2020 17:29:05 +0000 Subject: 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 --- src/lib/libcrypto/asn1/x_info.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c index c476923158..9285e3e289 100644 --- a/src/lib/libcrypto/asn1/x_info.c +++ b/src/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 #include -#include #include 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); } -- cgit v1.2.3-55-g6feb