From 2bf03ab7df6b9fbc0aef2e12cd5ca4ca2a839d94 Mon Sep 17 00:00:00 2001 From: Matthijs Mekking Date: Tue, 15 Aug 2023 12:20:40 +0200 Subject: [PATCH] Refactor dnssec-ksr Refactor some more, making the cleanup a generic function. --- bin/dnssec/dnssec-ksr.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/bin/dnssec/dnssec-ksr.c b/bin/dnssec/dnssec-ksr.c index fd28d1bed7..2c631cfe56 100644 --- a/bin/dnssec/dnssec-ksr.c +++ b/bin/dnssec/dnssec-ksr.c @@ -211,6 +211,17 @@ setcontext(ksr_ctx_t *ksr, dns_kasp_t *kasp) { ksr->ttlsig = dns_kasp_zonemaxttl(kasp, true); } +static void +cleanup(dns_dnsseckeylist_t *keys, dns_kasp_t *kasp) { + while (!ISC_LIST_EMPTY(*keys)) { + dns_dnsseckey_t *key = ISC_LIST_HEAD(*keys); + ISC_LIST_UNLINK(*keys, key, link); + dst_key_free(&key->key); + dns_dnsseckey_destroy(mctx, &key); + } + dns_kasp_detach(&kasp); +} + static void progress(int p) { char c = '*'; @@ -567,13 +578,7 @@ keygen(ksr_ctx_t *ksr) { fatal("policy '%s' has no zsks", ksr->policy); } /* Cleanup */ - while (!ISC_LIST_EMPTY(keys)) { - dns_dnsseckey_t *key = ISC_LIST_HEAD(keys); - ISC_LIST_UNLINK(keys, key, link); - dst_key_free(&key->key); - dns_dnsseckey_destroy(mctx, &key); - } - dns_kasp_detach(&kasp); + cleanup(&keys, kasp); } static void @@ -630,12 +635,7 @@ request(ksr_ctx_t *ksr) { inception = next; } /* Cleanup */ - while (!ISC_LIST_EMPTY(keys)) { - dns_dnsseckey_t *key = ISC_LIST_HEAD(keys); - ISC_LIST_UNLINK(keys, key, link); - dst_key_free(&key->key); - dns_dnsseckey_destroy(mctx, &key); - } + cleanup(&keys, kasp); } int