Tomas Hozza 230113
diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c
Tomas Hozza 230113
index 7023a82..d7f817c 100644
Tomas Hozza 230113
--- a/lib/dns/resolver.c
Tomas Hozza 230113
+++ b/lib/dns/resolver.c
Tomas Hozza 230113
@@ -351,6 +351,7 @@ typedef struct {
Tomas Hozza 230113
 
Tomas Hozza 230113
 struct dns_fetch {
Tomas Hozza 230113
 	unsigned int			magic;
Tomas Hozza 230113
+	isc_mem_t *			mctx;
Tomas Hozza 230113
 	fetchctx_t *			private;
Tomas Hozza 230113
 };
Tomas Hozza 230113
 
Tomas Hozza 230113
@@ -8416,6 +8417,8 @@ dns_resolver_createfetch2(dns_resolver_t *res, dns_name_t *name,
Tomas Hozza 230113
 	fetch = isc_mem_get(res->mctx, sizeof(*fetch));
Tomas Hozza 230113
 	if (fetch == NULL)
Tomas Hozza 230113
 		return (ISC_R_NOMEMORY);
Tomas Hozza 230113
+	fetch->mctx = NULL;
Tomas Hozza 230113
+	isc_mem_attach(res->mctx, &fetch->mctx);
Tomas Hozza 230113
 
Tomas Hozza 230113
 	bucketnum = dns_name_fullhash(name, ISC_FALSE) % res->nbuckets;
Tomas Hozza 230113
 
Tomas Hozza 230113
@@ -8506,7 +8509,7 @@ dns_resolver_createfetch2(dns_resolver_t *res, dns_name_t *name,
Tomas Hozza 230113
 		FTRACE("created");
Tomas Hozza 230113
 		*fetchp = fetch;
Tomas Hozza 230113
 	} else
Tomas Hozza 230113
-		isc_mem_put(res->mctx, fetch, sizeof(*fetch));
Tomas Hozza 230113
+		isc_mem_putanddetach(&fetch->mctx, fetch, sizeof(*fetch));
Tomas Hozza 230113
 
Tomas Hozza 230113
 	return (result);
Tomas Hozza 230113
 }
Tomas Hozza 230113
@@ -8597,7 +8600,7 @@ dns_resolver_destroyfetch(dns_fetch_t **fetchp) {
Tomas Hozza 230113
 
Tomas Hozza 230113
 	UNLOCK(&res->buckets[bucketnum].lock);
Tomas Hozza 230113
 
Tomas Hozza 230113
-	isc_mem_put(res->mctx, fetch, sizeof(*fetch));
Tomas Hozza 230113
+	isc_mem_putanddetach(&fetch->mctx, fetch, sizeof(*fetch));
Tomas Hozza 230113
 	*fetchp = NULL;
Tomas Hozza 230113
 
Tomas Hozza 230113
 	if (bucket_empty)