From 9e185cd611e2f7f245b63dd02fa46bda9cc32875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 9 Jan 2023 16:00:18 +0100 Subject: [PATCH] BN_free() and BN_clear_free() both accept NULL Remove the extra check in opensslrsa_components_free() as both BN_free() and BN_clear_free() both accepts NULL as valid argument and do nothing. --- lib/dns/opensslrsa_link.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/lib/dns/opensslrsa_link.c b/lib/dns/opensslrsa_link.c index 221e9e1723..7ee70eebfe 100644 --- a/lib/dns/opensslrsa_link.c +++ b/lib/dns/opensslrsa_link.c @@ -144,30 +144,21 @@ opensslrsa_components_free(rsa_components_t *c) { if (!c->bnfree) { return; } - if (c->e != NULL) { - BN_free((BIGNUM *)c->e); - } - if (c->n != NULL) { - BN_free((BIGNUM *)c->n); - } - if (c->d != NULL) { - BN_clear_free((BIGNUM *)c->d); - } - if (c->p != NULL) { - BN_clear_free((BIGNUM *)c->p); - } - if (c->q != NULL) { - BN_clear_free((BIGNUM *)c->q); - } - if (c->dmp1 != NULL) { - BN_clear_free((BIGNUM *)c->dmp1); - } - if (c->dmq1 != NULL) { - BN_clear_free((BIGNUM *)c->dmq1); - } - if (c->iqmp != NULL) { - BN_clear_free((BIGNUM *)c->iqmp); - } + /* + * NOTE: BN_free() frees the components of the BIGNUM, and if it was + * created by BN_new(), also the structure itself. BN_clear_free() + * additionally overwrites the data before the memory is returned to the + * system. If a is NULL, nothing is done. + */ + BN_free((BIGNUM *)c->e); + BN_free((BIGNUM *)c->n); + BN_clear_free((BIGNUM *)c->d); + BN_clear_free((BIGNUM *)c->p); + BN_clear_free((BIGNUM *)c->q); + BN_clear_free((BIGNUM *)c->dmp1); + BN_clear_free((BIGNUM *)c->dmq1); + BN_clear_free((BIGNUM *)c->iqmp); + c->bnfree = false; } static bool