From d7aba84628df7f82a1a1255c941459e4b40c7b47 Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 5 Nov 2021 17:03:15 +0000 Subject: [PATCH] Cleanup X509_LOOKUP_new() Switch from malloc() to calloc() and drop a bunch of initializations to 0. Call the returned object lu instead of the generic ret. ok jsing --- lib/libcrypto/x509/x509_lu.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/libcrypto/x509/x509_lu.c b/lib/libcrypto/x509/x509_lu.c index 8290f896577..f0a86f0adf6 100644 --- a/lib/libcrypto/x509/x509_lu.c +++ b/lib/libcrypto/x509/x509_lu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_lu.c,v 1.38 2021/11/05 07:25:36 tb Exp $ */ +/* $OpenBSD: x509_lu.c,v 1.39 2021/11/05 17:03:15 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -70,22 +70,21 @@ static void X509_OBJECT_dec_ref_count(X509_OBJECT *a); X509_LOOKUP * X509_LOOKUP_new(X509_LOOKUP_METHOD *method) { - X509_LOOKUP *ret; + X509_LOOKUP *lu; - ret = malloc(sizeof(X509_LOOKUP)); - if (ret == NULL) + if ((lu = calloc(1, sizeof(*lu))) == NULL) { + X509error(ERR_R_MALLOC_FAILURE); return NULL; + } - ret->init = 0; - ret->skip = 0; - ret->method = method; - ret->method_data = NULL; - ret->store_ctx = NULL; - if ((method->new_item != NULL) && !method->new_item(ret)) { - free(ret); + lu->method = method; + + if (method->new_item != NULL && !method->new_item(lu)) { + free(lu); return NULL; } - return ret; + + return lu; } void -- 2.20.1