From cabe3aee3bd61d408f15eae2e6b9091ba6d54e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 17 Dec 2025 06:59:33 +0100 Subject: [PATCH] Add dns_rdataset_cleanup() that conditionally disassociate rdataset We had a common pattern in the code that looks like this: if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); } add a helper macro that checks for rdataset != NULL and the above called dns_rdataset_cleanup(rdataset). --- lib/dns/include/dns/rdataset.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/dns/include/dns/rdataset.h b/lib/dns/include/dns/rdataset.h index 49b8a9e1a3..17f5eff088 100644 --- a/lib/dns/include/dns/rdataset.h +++ b/lib/dns/include/dns/rdataset.h @@ -285,6 +285,10 @@ dns_rdataset_invalidate(dns_rdataset_t *rdataset); * without initializing it will cause an assertion failure. */ +#define dns_rdataset_cleanup(rdataset) \ + if (rdataset != NULL && dns_rdataset_isassociated(rdataset)) { \ + dns__rdataset_disassociate(rdataset DNS__DB_FILELINE); \ + } #define dns_rdataset_disassociate(rdataset) \ dns__rdataset_disassociate(rdataset DNS__DB_FILELINE) void