diff --git a/bin/named/server.c b/bin/named/server.c index 97b4118d3b..fe65ddbae9 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -4740,18 +4740,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, * view but is not yet configured. If it is not the * view name but not a forward reference either, then it * is simply a named cache that is not shared. - * - * We use two separate memory contexts for the - * cache, for the main cache memory and the heap - * memory. */ - isc_mem_create(&cmctx); - isc_mem_setname(cmctx, "cache"); - CHECK(dns_cache_create(cmctx, named_g_taskmgr, + CHECK(dns_cache_create(mctx, named_g_taskmgr, named_g_timermgr, view->rdclass, cachename, "rbt", 0, NULL, &cache)); - isc_mem_detach(&cmctx); } nsc = isc_mem_get(mctx, sizeof(*nsc)); nsc->cache = NULL; diff --git a/lib/dns/cache.c b/lib/dns/cache.c index 40732e9180..cb7f35a95f 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -127,7 +127,7 @@ struct dns_cache { /* 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_taskmgr_t *taskmgr; @@ -331,7 +331,7 @@ cache_free(dns_cache_t *cache) { } isc_result_t -dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr, +dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, isc_timermgr_t *timermgr, dns_rdataclass_t rdclass, const char *cachename, const char *db_type, unsigned int db_argc, char **db_argv, dns_cache_t **cachep) { @@ -341,31 +341,31 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr, REQUIRE(cachep != NULL); REQUIRE(*cachep == NULL); - REQUIRE(cmctx != NULL); + REQUIRE(mctx != NULL); REQUIRE(taskmgr != NULL || strcmp(db_type, "rbt") != 0); REQUIRE(cachename != NULL); - cache = isc_mem_get(cmctx, sizeof(*cache)); + cache = isc_mem_get(mctx, sizeof(*cache)); *cache = (dns_cache_t){ - .db_type = isc_mem_strdup(cmctx, db_type), + .db_type = isc_mem_strdup(mctx, db_type), .rdclass = rdclass, .db_argc = db_argc, .name = cachename == NULL ? NULL - : isc_mem_strdup(cmctx, cachename), + : isc_mem_strdup(mctx, cachename), .magic = CACHE_MAGIC, }; - isc_mem_attach(cmctx, &cache->mctx); + isc_mutex_init(&cache->lock); + isc_mem_attach(mctx, &cache->mctx); if (taskmgr != NULL) { isc_taskmgr_attach(taskmgr, &cache->taskmgr); } - isc_mutex_init(&cache->lock); isc_refcount_init(&cache->references, 1); isc_refcount_init(&cache->live_tasks, 1); - result = isc_stats_create(cmctx, &cache->stats, + result = isc_stats_create(mctx, &cache->stats, dns_cachestatscounter_max); if (result != ISC_R_SUCCESS) { goto cleanup; @@ -382,7 +382,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr, } if (cache->db_argc != 0) { - cache->db_argv = isc_mem_get(cmctx, + cache->db_argv = isc_mem_get(mctx, cache->db_argc * sizeof(char *)); for (i = 0; i < cache->db_argc; i++) { @@ -390,7 +390,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr, } for (i = extra; i < cache->db_argc; i++) { - cache->db_argv[i] = isc_mem_strdup(cmctx, + cache->db_argv[i] = isc_mem_strdup(mctx, db_argv[i - extra]); } } diff --git a/lib/dns/include/dns/cache.h b/lib/dns/include/dns/cache.h index 5b15a79c7c..e5c6e49be9 100644 --- a/lib/dns/include/dns/cache.h +++ b/lib/dns/include/dns/cache.h @@ -56,7 +56,7 @@ ISC_LANG_BEGINDECLS *** Functions ***/ isc_result_t -dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr, +dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, isc_timermgr_t *timermgr, dns_rdataclass_t rdclass, const char *cachename, const char *db_type, unsigned int db_argc, char **db_argv, dns_cache_t **cachep); @@ -68,7 +68,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr, * * Requires: * - *\li 'cmctx' are valid memory contexts. + *\li 'mctx' is a valid memory context. * *\li 'taskmgr' is a valid task manager (if 'db_type' is "rbt"). * @@ -77,6 +77,8 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr, * periodic cleaning of the cache will take place. * *\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 *