2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

Pass a memory context in to dns_cache_create

This commit is contained in:
Mark Andrews
2024-03-27 11:32:25 +11:00
parent 5e77edd074
commit 87e3b9dbf3
5 changed files with 9 additions and 14 deletions

View File

@@ -2151,7 +2151,7 @@ run_server(void *arg) {
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);

View File

@@ -4671,7 +4671,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
* 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;

View File

@@ -66,7 +66,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_loop_t *loop;
@@ -160,24 +160,16 @@ cache_destroy(dns_cache_t *cache) {
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)),
@@ -186,6 +178,7 @@ dns_cache_create(isc_loopmgr_t *loopmgr, dns_rdataclass_t rdclass,
};
isc_mutex_init(&cache->lock);
isc_mem_attach(mctx, &cache->mctx);
isc_stats_create(mctx, &cache->stats, dns_cachestatscounter_max);

View File

@@ -73,7 +73,7 @@ ISC_REFCOUNT_DECL(dns_cache);
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.
*
@@ -84,6 +84,8 @@ dns_cache_create(isc_loopmgr_t *loopmgr, dns_rdataclass_t rdclass,
*\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
*

View File

@@ -84,7 +84,7 @@ dns_test_makeview(const char *name, bool with_dispatchmgr, bool with_cache,
}
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);