CHECK(dns_view_create(mctx, dispatchmgr, dns_rdataclass_in, "_default",
&view));
- CHECK(dns_cache_create(loopmgr, dns_rdataclass_in, "", &cache));
+ CHECK(dns_cache_create(loopmgr, dns_rdataclass_in, "", mctx, &cache));
dns_view_setcache(view, cache, false);
dns_cache_detach(&cache);
dns_view_setdstport(view, destport);
* is simply a named cache that is not shared.
*/
CHECK(dns_cache_create(named_g_loopmgr, view->rdclass,
- cachename, &cache));
+ cachename, mctx, &cache));
}
nsc = isc_mem_get(mctx, sizeof(*nsc));
nsc->cache = NULL;
/* Unlocked. */
unsigned int magic;
isc_mutex_t lock;
- isc_mem_t *mctx; /* Main cache memory */
+ isc_mem_t *mctx; /* Memory context for the dns_cache object */
isc_mem_t *hmctx; /* Heap memory */
isc_mem_t *tmctx; /* Tree memory */
isc_loop_t *loop;
isc_result_t
dns_cache_create(isc_loopmgr_t *loopmgr, dns_rdataclass_t rdclass,
- const char *cachename, dns_cache_t **cachep) {
+ const char *cachename, isc_mem_t *mctx, dns_cache_t **cachep) {
isc_result_t result;
dns_cache_t *cache = NULL;
- isc_mem_t *mctx = NULL;
REQUIRE(loopmgr != NULL);
REQUIRE(cachename != NULL);
REQUIRE(cachep != NULL && *cachep == NULL);
- /*
- * Self.
- */
- isc_mem_create(&mctx);
- isc_mem_setname(mctx, "cache-self");
-
cache = isc_mem_get(mctx, sizeof(*cache));
*cache = (dns_cache_t){
- .mctx = mctx,
.rdclass = rdclass,
.name = isc_mem_strdup(mctx, cachename),
.loop = isc_loop_ref(isc_loop_main(loopmgr)),
};
isc_mutex_init(&cache->lock);
+ isc_mem_attach(mctx, &cache->mctx);
isc_stats_create(mctx, &cache->stats, dns_cachestatscounter_max);
isc_result_t
dns_cache_create(isc_loopmgr_t *loopmgr, dns_rdataclass_t rdclass,
- const char *cachename, dns_cache_t **cachep);
+ const char *cachename, isc_mem_t *mctx, dns_cache_t **cachep);
/*%<
* Create a new DNS cache.
*
*\li 'loopmgr' is a valid loop manager.
*
*\li 'cachename' is a valid string. This must not be NULL.
+
+ *\li 'mctx' is a valid memory context.
*
*\li 'cachep' is a valid pointer, and *cachep == NULL
*
}
if (with_cache) {
- result = dns_cache_create(loopmgr, dns_rdataclass_in, "",
+ result = dns_cache_create(loopmgr, dns_rdataclass_in, "", mctx,
&cache);
if (result != ISC_R_SUCCESS) {
dns_view_detach(&view);