From f2855facbeb19c51befed1c858f4d28b8306f886 Mon Sep 17 00:00:00 2001
From: Mark Andrews <marka@isc.org>
Date: Tue, 21 Dec 2021 12:44:17 +1100
Subject: [PATCH] disassociate rdatasets when cleaning up

free_namelist could be passed names with associated rdatasets
when handling errors.  These need to be disassociated before
calling dns_message_puttemprdataset.

(cherry picked from commit 745d5edc3a8ca6f232b2d700ae076c2caee2bfc5)
---
 lib/dns/tkey.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/dns/tkey.c b/lib/dns/tkey.c
index e6e44526a9c..9259a513188 100644
--- a/lib/dns/tkey.c
+++ b/lib/dns/tkey.c
@@ -226,6 +226,9 @@ free_namelist(dns_message_t *msg, dns_namelist_t *namelist) {
 		while (!ISC_LIST_EMPTY(name->list)) {
 			set = ISC_LIST_HEAD(name->list);
 			ISC_LIST_UNLINK(name->list, set, link);
+			if (dns_rdataset_isassociated(set)) {
+				dns_rdataset_disassociate(set);
+			}
 			dns_message_puttemprdataset(msg, &set);
 		}
 		dns_message_puttempname(msg, &name);
-- 
GitLab

