]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Pass a memory context in to dns_cache_create
authorMark Andrews <marka@isc.org>
Wed, 27 Mar 2024 00:32:25 +0000 (11:32 +1100)
committerMark Andrews <marka@isc.org>
Fri, 31 May 2024 05:40:32 +0000 (15:40 +1000)
bin/delv/delv.c
bin/named/server.c
lib/dns/cache.c
lib/dns/include/dns/cache.h
tests/libtest/dns.c

index a767c0cffa4c6eca56e2624e8276bb078e2346a8..e06322de11d650653533619af3e05592a63a9629 100644 (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);
index f972dce906c76f10aeb5d61890614ad7bf787454..a17375dbaaaf9c3619ecb8e444812ccaef286c01 100644 (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;
index 28bb6d297c0e18e18c1875f1329a7fa3e66a0bb4..e9e677c40b193719ca3cb26135b27e93347d3c96 100644 (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);
 
index 103e5cbf7ee6604b3f7e90292785500957e9e94c..72cf80c3f47a49ffbf63d529adb2aee5f18b12f8 100644 (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
  *
index e57a6820e8da923eadea6bbd949b482bef4082a1..8dd1bbc5e53ba9b5d1a03465252ea45dec211710 100644 (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);